R1000 commited on
Commit
7dab0d9
·
verified ·
1 Parent(s): 43968c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ OLLAMA_API = "http://localhost:11434/api/chat"
5
+
6
+ def chat_fn(message, history):
7
+ messages = [{"role": "user", "content": message}]
8
+ payload = {
9
+ "model": "qwen2.5-coder:3b", # หรือเปลี่ยน model ตามที่ pull มา
10
+ "messages": messages
11
+ }
12
+ try:
13
+ response = requests.post(OLLAMA_API, json=payload)
14
+ response.raise_for_status()
15
+ data = response.json()
16
+ reply = data.get("message", {}).get("content", "No response.")
17
+ return reply
18
+ except Exception as e:
19
+ return f"Error: {e}"
20
+
21
+ gr.ChatInterface(chat_fn, title="Chat with Ollama Model").launch()