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