Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 13 |
from pydantic import BaseModel
|
| 14 |
import uvicorn
|
| 15 |
import json
|
|
|
|
| 16 |
|
| 17 |
# Disable SSL warnings
|
| 18 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
@@ -200,8 +201,30 @@ async def search_endpoint(request: SearchRequest):
|
|
| 200 |
|
| 201 |
raise HTTPException(status_code=500, detail=error_response)
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
if __name__ == "__main__":
|
| 204 |
-
|
| 205 |
-
print("🚀 Starting Search Assistant Server...")
|
| 206 |
-
print(f"📱 Port: {port}")
|
| 207 |
-
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
|
|
| 13 |
from pydantic import BaseModel
|
| 14 |
import uvicorn
|
| 15 |
import json
|
| 16 |
+
import gradio as gr
|
| 17 |
|
| 18 |
# Disable SSL warnings
|
| 19 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
| 201 |
|
| 202 |
raise HTTPException(status_code=500, detail=error_response)
|
| 203 |
|
| 204 |
+
def gradio_search(question, mode):
|
| 205 |
+
import requests
|
| 206 |
+
try:
|
| 207 |
+
resp = requests.post(
|
| 208 |
+
"/search", # Internal call on Spaces
|
| 209 |
+
json={"question": question, "mode": mode},
|
| 210 |
+
timeout=60
|
| 211 |
+
)
|
| 212 |
+
data = resp.json()
|
| 213 |
+
answer = data.get("answer", "")
|
| 214 |
+
sources = data.get("sources", [])
|
| 215 |
+
sources_md = "\n".join([f"- [{src['title']}]({src['url']})" for src in sources])
|
| 216 |
+
return answer, sources_md
|
| 217 |
+
except Exception as e:
|
| 218 |
+
return f"Error: {e}", ""
|
| 219 |
+
|
| 220 |
+
with gr.Blocks() as demo:
|
| 221 |
+
gr.Markdown("# Search Assistant")
|
| 222 |
+
question = gr.Textbox(label="Question", placeholder="Ask anything...")
|
| 223 |
+
mode = gr.Radio(choices=["quick", "deep"], value="quick", label="Mode")
|
| 224 |
+
answer = gr.Markdown(label="Answer")
|
| 225 |
+
sources = gr.Markdown(label="Sources")
|
| 226 |
+
btn = gr.Button("Search")
|
| 227 |
+
btn.click(gradio_search, inputs=[question, mode], outputs=[answer, sources])
|
| 228 |
+
|
| 229 |
if __name__ == "__main__":
|
| 230 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", 7860)))
|
|
|
|
|
|
|
|
|