File size: 783 Bytes
b488104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5aa9f4a
 
b488104
 
5aa9f4a
b488104
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
import requests

FASTAPI_URL = "http://localhost:7860/ask_ollama/"

def ask_ollama(question):
    response = requests.get(f"{FASTAPI_URL}?question={question}")
    if response.status_code == 200:
        return response.json().get("response", "No response from Ollama.")
    return "Error: Could not connect to API."

# Create Gradio interface
iface = gr.Interface(
    fn=ask_ollama,
    inputs=gr.Textbox(placeholder="Ask a question..."),
    outputs="text",
    title="Ollama Chat",
    description="Ask anything and get responses from the Ollama model.",
    flagging_dir=None  # 🔹 Disable flagging to avoid permission issues
)


# Run on port 7861 (so FastAPI and Gradio can run together)
iface.launch(server_name="0.0.0.0", server_port=7861, share=True)