File size: 1,071 Bytes
a1411fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
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)