Spaces:
Runtime error
Runtime error
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." | |
) | |
# Run on port 7861 (so FastAPI and Gradio can run together) | |
iface.launch(server_name="0.0.0.0", server_port=7861, share=True) | |