Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,30 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
2 |
import torch
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
-
#
|
6 |
-
model_id = "
|
7 |
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
-
model = AutoModelForCausalLM.from_pretrained(
|
10 |
-
model_id,
|
11 |
-
torch_dtype=torch.float16, # CPU çalışıyorsan float32 olabilir
|
12 |
-
device_map="auto"
|
13 |
-
)
|
14 |
|
15 |
def generate_question(memory):
|
16 |
-
prompt = f"
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
#
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_question,
|
25 |
inputs=gr.Textbox(label="Your Memory"),
|
26 |
outputs=gr.Textbox(label="Generated Question"),
|
27 |
-
title="
|
28 |
)
|
29 |
|
30 |
iface.launch()
|
|
|
|
|
1 |
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Model yükleme (hafif!)
|
6 |
+
model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
7 |
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def generate_question(memory):
|
12 |
+
prompt = f"<|system|>You are a helpful assistant that generates meaningful questions from memories.<|user|>Memory: {memory}\nGenerate a related question.<|assistant|>"
|
13 |
+
|
14 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
15 |
+
output_ids = model.generate(input_ids, max_new_tokens=50, do_sample=True)
|
16 |
+
result = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
17 |
+
|
18 |
+
# Cevabın son kısmını al
|
19 |
+
question = result.split("<|assistant|>")[-1].strip()
|
20 |
+
return question
|
21 |
|
22 |
+
# Gradio UI
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_question,
|
25 |
inputs=gr.Textbox(label="Your Memory"),
|
26 |
outputs=gr.Textbox(label="Generated Question"),
|
27 |
+
title="TinyLLaMA Memory Question Generator"
|
28 |
)
|
29 |
|
30 |
iface.launch()
|