SamiKoen commited on
Commit
246e061
·
1 Parent(s): 26b34bc

Add Gradio API endpoint for conversations

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -1080,6 +1080,17 @@ def enhanced_chatbot_fn(message, history, image):
1080
  return chatbot_fn(message, history, image)
1081
 
1082
  # Demo arayüzü - Mobil responsive
 
 
 
 
 
 
 
 
 
 
 
1083
  with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storage_js) as demo:
1084
  gr.Markdown("# 🚲 Trek Asistanı AI")
1085
  gr.Markdown("**Akıllı özellikler:** Ürün karşılaştırması ve detaylı ürün bilgileri sunuyorum.")
@@ -1147,7 +1158,15 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storag
1147
  chat_history[-1]["content"] = error_msg
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
 
@@ -1199,5 +1218,5 @@ if __name__ == "__main__":
1199
  server_name="0.0.0.0",
1200
  server_port=7860,
1201
  share=False,
1202
- show_api=False
1203
  )
 
1080
  return chatbot_fn(message, history, image)
1081
 
1082
  # Demo arayüzü - Mobil responsive
1083
+
1084
+ # Function to get conversations for API
1085
+ def get_conversations_api():
1086
+ """Get all conversations as JSON for dashboard"""
1087
+ try:
1088
+ from conversation_tracker import load_conversations
1089
+ conversations = load_conversations()
1090
+ return conversations
1091
+ except Exception as e:
1092
+ return [{"error": str(e)}]
1093
+
1094
  with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storage_js) as demo:
1095
  gr.Markdown("# 🚲 Trek Asistanı AI")
1096
  gr.Markdown("**Akıllı özellikler:** Ürün karşılaştırması ve detaylı ürün bilgileri sunuyorum.")
 
1158
  chat_history[-1]["content"] = error_msg
1159
  yield "", chat_history
1160
 
1161
+
1162
+ # Hidden API endpoint for conversations
1163
+ with gr.Row(visible=False):
1164
+ api_btn = gr.Button("Get Conversations", elem_id="api_btn")
1165
+ api_output = gr.JSON(label="Conversations")
1166
+
1167
+ api_btn.click(fn=get_conversations_api, outputs=api_output, api_name="get_conversations")
1168
+
1169
+ msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
1170
 
1171
  # API will be handled separately in production
1172
 
 
1218
  server_name="0.0.0.0",
1219
  server_port=7860,
1220
  share=False,
1221
+ show_api=True
1222
  )