Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +75 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""huggingface.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/149y_UsrqsIDR7_OwRgNnRfs-KkGhFvtx
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
|
| 12 |
+
generator = pipeline("text-generation",
|
| 13 |
+
model= "Qwen/Qwen3-4B-Instruct-2507",
|
| 14 |
+
torch_dtype="auto",
|
| 15 |
+
device_map="auto")
|
| 16 |
+
|
| 17 |
+
output = generator("Hi how are you?")
|
| 18 |
+
print(output[0]["generated_text"])
|
| 19 |
+
|
| 20 |
+
messages = [
|
| 21 |
+
{"role": "system", "content": "You are a helpful AI assistant."},
|
| 22 |
+
{"role": "user", "content": "Tell me a short joke"}]
|
| 23 |
+
|
| 24 |
+
outputs = generator(
|
| 25 |
+
messages,
|
| 26 |
+
max_new_tokens=100,
|
| 27 |
+
do_sample=True,
|
| 28 |
+
temperature=0.7,
|
| 29 |
+
return_full_text=False
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
print(outputs[0]["generated_text"])
|
| 33 |
+
|
| 34 |
+
messages = [
|
| 35 |
+
{
|
| 36 |
+
"role": "system",
|
| 37 |
+
"content": "Sen Türkçe cevap veren, yardımcı bir yapay zeka asistansın."
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"role": "user",
|
| 41 |
+
"content": "Üretken yapay zeka nedir kısaca cevap ver"
|
| 42 |
+
}
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
outputs = generator(
|
| 46 |
+
messages,
|
| 47 |
+
max_new_tokens=100,
|
| 48 |
+
do_sample=True,
|
| 49 |
+
temperature=0.7,
|
| 50 |
+
return_full_text=False
|
| 51 |
+
)
|
| 52 |
+
print(outputs[0]["generated_text"])
|
| 53 |
+
|
| 54 |
+
import gradio as gr
|
| 55 |
+
|
| 56 |
+
def generate_text(prompt):
|
| 57 |
+
messages = [
|
| 58 |
+
{"role": "system", "content": "Sen Türkçe cevap veren, yardımcı bir yapay zeka asistansın."},
|
| 59 |
+
{"role": "user", "content": prompt}]
|
| 60 |
+
outputs = generator(
|
| 61 |
+
messages,
|
| 62 |
+
max_new_tokens=200,
|
| 63 |
+
do_sample=True,
|
| 64 |
+
temperature=0.7,
|
| 65 |
+
return_full_text=False
|
| 66 |
+
)
|
| 67 |
+
return outputs[0]["generated_text"]
|
| 68 |
+
|
| 69 |
+
demo = gr.Interface(
|
| 70 |
+
fn=generate_text,
|
| 71 |
+
inputs=gr.Textbox(label="Give an input"),
|
| 72 |
+
outputs=gr.Textbox(label="Output"),
|
| 73 |
+
title="Text Generation",)
|
| 74 |
+
demo.launch()
|
| 75 |
+
|
requirements.txt
ADDED
|
File without changes
|