Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta"
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
# Chat formatı
|
| 9 |
-
prompt = f"<|system|>\nYou are a helpful assistant for generating song lyrics.\n<|user|>\n{message}\n<|assistant|>\n"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Gradio arayüzü
|
| 20 |
with gr.Blocks() as demo:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Basitleştirilmiş pipeline (CPU dostu)
|
| 5 |
+
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
# Chat formatı
|
| 9 |
+
prompt = f"<|system|>\nYou are a helpful assistant for generating song lyrics in Turkish or English.\n<|user|>\n{message}\n<|assistant|>\n"
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
response = pipe(prompt, max_new_tokens=150, do_sample=True, temperature=0.7, pad_token_id=pipe.tokenizer.eos_token_id)[0]['generated_text']
|
| 13 |
+
|
| 14 |
+
# Sadece assistant kısmını döndür
|
| 15 |
+
if "<|assistant|>" in response:
|
| 16 |
+
response = response.split("<|assistant|>")[1].strip()
|
| 17 |
+
|
| 18 |
+
return response
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"Hata: {str(e)}"
|
| 21 |
|
| 22 |
# Gradio arayüzü
|
| 23 |
with gr.Blocks() as demo:
|