SamiKoen
commited on
Commit
·
26b34bc
1
Parent(s):
0b48047
Add allowed_paths for file serving
Browse files
app.py
CHANGED
|
@@ -1148,47 +1148,54 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storag
|
|
| 1148 |
yield "", chat_history
|
| 1149 |
|
| 1150 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
| 1151 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
| 1152 |
-
|
| 1153 |
-
# API endpoints - Module level setup
|
| 1154 |
-
from fastapi import Request
|
| 1155 |
-
from fastapi.responses import JSONResponse
|
| 1156 |
-
|
| 1157 |
-
# Get Gradio's underlying FastAPI app (created when Blocks is defined)
|
| 1158 |
-
# In Gradio 5+, demo has .app attribute after the "with" block
|
| 1159 |
-
try:
|
| 1160 |
-
gradio_app = demo.app
|
| 1161 |
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
|
| 1172 |
-
|
| 1173 |
-
|
| 1174 |
-
|
| 1175 |
-
|
| 1176 |
-
|
| 1177 |
-
|
| 1178 |
-
|
| 1179 |
-
|
| 1180 |
-
|
| 1181 |
-
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
-
|
| 1186 |
-
|
| 1187 |
-
|
| 1188 |
-
|
| 1189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1190 |
if __name__ == "__main__":
|
| 1191 |
-
demo.launch(
|
| 1192 |
server_name="0.0.0.0",
|
| 1193 |
server_port=7860,
|
| 1194 |
share=False,
|
|
|
|
| 1148 |
yield "", chat_history
|
| 1149 |
|
| 1150 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1151 |
|
| 1152 |
+
# API will be handled separately in production
|
| 1153 |
+
|
| 1154 |
+
# FastAPI endpoints disabled for better HF Spaces compatibility
|
| 1155 |
+
# Use Gradio's built-in API instead
|
| 1156 |
+
|
| 1157 |
+
# from fastapi import FastAPI
|
| 1158 |
+
# from fastapi.middleware.cors import CORSMiddleware
|
| 1159 |
+
# from fastapi.responses import JSONResponse
|
| 1160 |
+
# import json
|
| 1161 |
+
|
| 1162 |
+
# # Create FastAPI app
|
| 1163 |
+
# api = FastAPI()
|
| 1164 |
+
|
| 1165 |
+
# # Add CORS middleware
|
| 1166 |
+
# api.add_middleware(
|
| 1167 |
+
# CORSMiddleware,
|
| 1168 |
+
# allow_origins=["*"], # Allow all origins
|
| 1169 |
+
# allow_credentials=True,
|
| 1170 |
+
# allow_methods=["*"],
|
| 1171 |
+
# allow_headers=["*"],
|
| 1172 |
+
# )
|
| 1173 |
+
|
| 1174 |
+
# @api.get("/api/conversations")
|
| 1175 |
+
# async def get_conversations():
|
| 1176 |
+
# """API endpoint to get conversations with CORS"""
|
| 1177 |
+
# try:
|
| 1178 |
+
# from conversation_tracker import load_conversations
|
| 1179 |
+
# conversations = load_conversations()
|
| 1180 |
+
# return JSONResponse(content=conversations)
|
| 1181 |
+
# except Exception as e:
|
| 1182 |
+
# return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 1183 |
+
|
| 1184 |
+
# @api.get("/api/conversations/latest")
|
| 1185 |
+
# async def get_latest_conversations():
|
| 1186 |
+
# """Get last 50 conversations"""
|
| 1187 |
+
# try:
|
| 1188 |
+
# from conversation_tracker import load_conversations
|
| 1189 |
+
# conversations = load_conversations()
|
| 1190 |
+
# return JSONResponse(content=conversations[-50:])
|
| 1191 |
+
# except Exception as e:
|
| 1192 |
+
# return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 1193 |
+
|
| 1194 |
+
|
| 1195 |
+
|
| 1196 |
+
# Use Gradio directly instead of mounting on FastAPI - Better for HF Spaces
|
| 1197 |
if __name__ == "__main__":
|
| 1198 |
+
demo.launch(allowed_paths=["/app/conversations.json", "/app/public"],
|
| 1199 |
server_name="0.0.0.0",
|
| 1200 |
server_port=7860,
|
| 1201 |
share=False,
|