carlosdimare commited on
Commit
daac006
·
verified ·
1 Parent(s): bca9e3a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ OLLAMA_MODEL = "qwen:0.5b"
5
+ OLLAMA_URL = "http://localhost:11434/api/generate"
6
+
7
+ def chat_with_qwen(message, history):
8
+ payload = {
9
+ "model": OLLAMA_MODEL,
10
+ "prompt": message,
11
+ "stream": False
12
+ }
13
+ try:
14
+ response = requests.post(OLLAMA_URL, json=payload, timeout=60)
15
+ response.raise_for_status()
16
+ return response.json().get("response", "Sin respuesta")
17
+ except Exception as e:
18
+ return f"Error: {e}"
19
+
20
+ iface = gr.ChatInterface(
21
+ fn=chat_with_qwen,
22
+ title="Chat con Qwen 0.5B (Ollama)",
23
+ description="Chatea con el modelo Qwen 0.5B usando Ollama en Hugging Face Spaces.",
24
+ theme="soft"
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch(server_name="0.0.0.0", server_port=7860)