Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Carrega o modelo
|
| 5 |
-
|
| 6 |
-
model_id = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 7 |
-
pipe = pipeline("text-generation", model=model_id, device_map="cpu")
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
# Formata a mensagem para o modelo
|
| 11 |
messages = [{"role": "user", "content": message}]
|
| 12 |
-
|
| 13 |
# Gera a resposta
|
| 14 |
-
results = pipe(messages, max_new_tokens=512
|
|
|
|
| 15 |
return results[0]['generated_text'][-1]['content']
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
demo = gr.ChatInterface(fn=
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Carrega o modelo na CPU
|
| 5 |
+
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device_map="cpu")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def predict(message, history):
|
|
|
|
| 8 |
messages = [{"role": "user", "content": message}]
|
|
|
|
| 9 |
# Gera a resposta
|
| 10 |
+
results = pipe(messages, max_new_tokens=512)
|
| 11 |
+
# Retorna apenas o texto da resposta
|
| 12 |
return results[0]['generated_text'][-1]['content']
|
| 13 |
|
| 14 |
+
# O segredo está aqui: Definimos o nome do endpoint como "chat"
|
| 15 |
+
demo = gr.ChatInterface(fn=predict).queue()
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|
| 18 |
demo.launch()
|