Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,12 @@ import gradio as gr
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from database import db
|
| 5 |
|
| 6 |
-
# Initialize HF Serverless Inference Client
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN", None)
|
| 8 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 9 |
|
| 10 |
def format_graph_context(records):
|
| 11 |
-
"""Formats retrieved graph records into readable LLM context."""
|
| 12 |
if not records:
|
| 13 |
return "No matching nodes found in Knowledge Graph.", ""
|
| 14 |
|
|
@@ -41,6 +41,9 @@ def format_graph_context(records):
|
|
| 41 |
|
| 42 |
def bot_respond(user_message, history):
|
| 43 |
"""Processes user input, queries CognoDB, and streams LLM response."""
|
|
|
|
|
|
|
|
|
|
| 44 |
if not user_message.strip():
|
| 45 |
yield history, "<i>No query entered.</i>"
|
| 46 |
return
|
|
@@ -108,7 +111,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
| 108 |
|
| 109 |
with gr.Row():
|
| 110 |
with gr.Column(scale=3):
|
| 111 |
-
|
|
|
|
| 112 |
msg_input = gr.Textbox(
|
| 113 |
placeholder="Ask a question (e.g., 'How do I fix 401 unauthorized errors?')...",
|
| 114 |
show_label=False
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from database import db
|
| 5 |
|
| 6 |
+
# Initialize HF Serverless Inference Client
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN", None)
|
| 8 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 9 |
|
| 10 |
def format_graph_context(records):
|
| 11 |
+
"""Formats retrieved graph records into readable LLM context and UI HTML."""
|
| 12 |
if not records:
|
| 13 |
return "No matching nodes found in Knowledge Graph.", ""
|
| 14 |
|
|
|
|
| 41 |
|
| 42 |
def bot_respond(user_message, history):
|
| 43 |
"""Processes user input, queries CognoDB, and streams LLM response."""
|
| 44 |
+
if history is None:
|
| 45 |
+
history = []
|
| 46 |
+
|
| 47 |
if not user_message.strip():
|
| 48 |
yield history, "<i>No query entered.</i>"
|
| 49 |
return
|
|
|
|
| 111 |
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Column(scale=3):
|
| 114 |
+
# FIXED: Removed type="messages" for Gradio 5/6 compatibility
|
| 115 |
+
chatbot = gr.Chatbot(height=420)
|
| 116 |
msg_input = gr.Textbox(
|
| 117 |
placeholder="Ask a question (e.g., 'How do I fix 401 unauthorized errors?')...",
|
| 118 |
show_label=False
|