import gradio as gr import sys, os # ─── Ensure utils/ is importable ────────────────────────────── ROOT_PATH = os.path.abspath(os.path.dirname(__file__)) if ROOT_PATH not in sys.path: sys.path.insert(0, ROOT_PATH) from utils.backend import run_llm # ─── Chatbot function ───────────────────────────────────────── def chat_fn(message, history): # Build context from history context = "\n".join([f"User: {u}\nAI: {a}" for u, a in history]) ai_input = context + "\nUser: " + message reply = run_llm(ai_input) return reply # ─── Launch Gradio ChatInterface ────────────────────────────── demo = gr.ChatInterface( fn=chat_fn, title="🤖 Omniscient Chatbot (Gradio)", description="Chatbot powered by HF API or Ollama backend.", ) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)