NexusInstruments commited on
Commit
a1411fc
·
verified ·
1 Parent(s): f4a81bc

Create gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +27 -0
gradio_app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import sys, os
3
+
4
+ # ─── Ensure utils/ is importable ──────────────────────────────
5
+ ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
6
+ if ROOT_PATH not in sys.path:
7
+ sys.path.insert(0, ROOT_PATH)
8
+
9
+ from utils.backend import run_llm
10
+
11
+ # ─── Chatbot function ─────────────────────────────────────────
12
+ def chat_fn(message, history):
13
+ # Build context from history
14
+ context = "\n".join([f"User: {u}\nAI: {a}" for u, a in history])
15
+ ai_input = context + "\nUser: " + message
16
+ reply = run_llm(ai_input)
17
+ return reply
18
+
19
+ # ─── Launch Gradio ChatInterface ──────────────────────────────
20
+ demo = gr.ChatInterface(
21
+ fn=chat_fn,
22
+ title="🤖 Omniscient Chatbot (Gradio)",
23
+ description="Chatbot powered by HF API or Ollama backend.",
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ demo.launch(server_name="0.0.0.0", server_port=7860)