Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,10 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Dwani.ai – Frontend UI
|
| 3 |
-
Perfectly aligned with RAG_backend
|
| 4 |
-
NO temp 404 errors
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
import gradio as gr
|
| 8 |
import requests
|
| 9 |
import time
|
| 10 |
|
| 11 |
-
# 🔴 MUST MATCH BACKEND SPACE
|
| 12 |
-
API_BASE = "https://sahana31-rag-backend.hf.space"
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
-
# ======================
|
| 16 |
-
# Backend Client
|
| 17 |
-
# ======================
|
| 18 |
class BackendClient:
|
| 19 |
def __init__(self, base_url):
|
| 20 |
self.base = base_url.rstrip("/")
|
|
@@ -60,9 +50,6 @@ class BackendClient:
|
|
| 60 |
client = BackendClient(API_BASE)
|
| 61 |
|
| 62 |
|
| 63 |
-
# ======================
|
| 64 |
-
# Helpers
|
| 65 |
-
# ======================
|
| 66 |
def wait_until_done(file_id, timeout=120):
|
| 67 |
for _ in range(timeout):
|
| 68 |
info = client.file_status(file_id)
|
|
@@ -74,9 +61,6 @@ def wait_until_done(file_id, timeout=120):
|
|
| 74 |
return False
|
| 75 |
|
| 76 |
|
| 77 |
-
# ======================
|
| 78 |
-
# Gradio Functions
|
| 79 |
-
# ======================
|
| 80 |
def upload_files(files, uploaded_state):
|
| 81 |
if not files:
|
| 82 |
return "⚠️ No files selected", [], uploaded_state, "**No files**"
|
|
@@ -158,9 +142,7 @@ def clear_chat():
|
|
| 158 |
return [], []
|
| 159 |
|
| 160 |
|
| 161 |
-
|
| 162 |
-
# UI
|
| 163 |
-
# ======================
|
| 164 |
with gr.Blocks(title="Dwani.ai") as demo:
|
| 165 |
gr.Markdown("# 📚 Dwani.ai – Document Chat")
|
| 166 |
|
|
@@ -213,4 +195,4 @@ with gr.Blocks(title="Dwani.ai") as demo:
|
|
| 213 |
outputs=[chatbot, chat_state],
|
| 214 |
)
|
| 215 |
|
| 216 |
-
demo.queue(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
API_BASE = "https://sahana31-rag-backend.hf.space"
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
class BackendClient:
|
| 9 |
def __init__(self, base_url):
|
| 10 |
self.base = base_url.rstrip("/")
|
|
|
|
| 50 |
client = BackendClient(API_BASE)
|
| 51 |
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
def wait_until_done(file_id, timeout=120):
|
| 54 |
for _ in range(timeout):
|
| 55 |
info = client.file_status(file_id)
|
|
|
|
| 61 |
return False
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
| 64 |
def upload_files(files, uploaded_state):
|
| 65 |
if not files:
|
| 66 |
return "⚠️ No files selected", [], uploaded_state, "**No files**"
|
|
|
|
| 142 |
return [], []
|
| 143 |
|
| 144 |
|
| 145 |
+
|
|
|
|
|
|
|
| 146 |
with gr.Blocks(title="Dwani.ai") as demo:
|
| 147 |
gr.Markdown("# 📚 Dwani.ai – Document Chat")
|
| 148 |
|
|
|
|
| 195 |
outputs=[chatbot, chat_state],
|
| 196 |
)
|
| 197 |
|
| 198 |
+
demo.queue()
|