Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,35 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def generate_text(prompt):
|
| 5 |
messages = [
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
outputs = generator(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
return outputs[0]["generated_text"]
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=generate_text,
|
| 19 |
inputs=gr.Textbox(label="Give an input"),
|
| 20 |
-
outputs=gr.Textbox(label="Output", lines=10),
|
| 21 |
-
title="Text Generation"
|
| 22 |
-
|
| 23 |
demo.launch()
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
generator = pipeline("text-generation",
|
| 5 |
+
model= "Qwen/Qwen3-4B-Instruct-2507",
|
| 6 |
+
dtype = "auto",
|
| 7 |
+
device_map="auto")
|
| 8 |
+
|
| 9 |
def generate_text(prompt):
|
| 10 |
messages = [
|
| 11 |
+
{
|
| 12 |
+
"role": "system",
|
| 13 |
+
"content": "Sen Türkçe cevap veren, yardımcı bir yapay zeka asistansın."
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"role": "user",
|
| 17 |
+
"content": prompt
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
outputs = generator(
|
| 21 |
+
messages,
|
| 22 |
+
max_new_tokens = 100,
|
| 23 |
+
do_sample = True,
|
| 24 |
+
temperature = 0.7,
|
| 25 |
+
return_full_text=False
|
| 26 |
+
)
|
| 27 |
return outputs[0]["generated_text"]
|
| 28 |
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=generate_text,
|
| 31 |
inputs=gr.Textbox(label="Give an input"),
|
| 32 |
+
outputs = gr.Textbox(label="Output", lines=10),
|
| 33 |
+
title = "Text Generation"
|
| 34 |
+
)
|
| 35 |
demo.launch()
|