SamiKoen commited on
Commit
09525e7
·
1 Parent(s): f6c6bf6

Add JSON endpoint for dashboard CORS fix

Browse files
Files changed (2) hide show
  1. app.py +13 -0
  2. static_files.py +18 -0
app.py CHANGED
@@ -1130,6 +1130,19 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storag
1130
 
1131
  msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
1132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1133
  # API endpoints for dashboard
1134
  def get_all_conversations():
1135
  """API endpoint to get all conversations"""
 
1130
 
1131
  msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
1132
 
1133
+ # Add a hidden component to serve conversations.json
1134
+ with gr.Row(visible=False):
1135
+ json_output = gr.JSON(label="Conversations")
1136
+ refresh_btn = gr.Button("Refresh JSON")
1137
+
1138
+ def get_conversations_json():
1139
+ from conversation_tracker import load_conversations
1140
+ return load_conversations()
1141
+
1142
+ refresh_btn.click(get_conversations_json, outputs=json_output)
1143
+ # Auto-load on start
1144
+ demo.load(get_conversations_json, outputs=json_output)
1145
+
1146
  # API endpoints for dashboard
1147
  def get_all_conversations():
1148
  """API endpoint to get all conversations"""
static_files.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Serve static files with CORS headers"""
2
+
3
+ import gradio as gr
4
+ from pathlib import Path
5
+ import json
6
+
7
+ def serve_conversations():
8
+ """Serve conversations.json with proper CORS headers"""
9
+ try:
10
+ with open('conversations.json', 'r') as f:
11
+ data = json.load(f)
12
+ return gr.JSON(data, headers={
13
+ "Access-Control-Allow-Origin": "*",
14
+ "Access-Control-Allow-Methods": "GET",
15
+ "Access-Control-Allow-Headers": "Content-Type"
16
+ })
17
+ except:
18
+ return {"error": "File not found"}