Fix Invalid port errors - remove FastAPI integration
Browse files- Removed FastAPI/uvicorn dependencies causing port conflicts
- Removed gr.mount_gradio_app that was causing Invalid port errors
- API endpoints now handled separately (can run with run_api.py if needed)
- Added conversation API functions to Gradio app (for future use)
- Cleaned up imports
The "Invalid port" errors were caused by trying to mount FastAPI on Gradio, which created routing conflicts.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- app.py +50 -6
- requirements.txt +0 -2
- run_api.py +8 -0
app.py
CHANGED
@@ -6,8 +6,6 @@ import xml.etree.ElementTree as ET
|
|
6 |
import schedule
|
7 |
import time
|
8 |
import threading
|
9 |
-
from fastapi import FastAPI
|
10 |
-
from fastapi.middleware.cors import CORSMiddleware
|
11 |
from huggingface_hub import HfApi, create_repo, hf_hub_download
|
12 |
import warnings
|
13 |
import pandas as pd
|
@@ -34,8 +32,7 @@ from image_renderer import extract_product_info_for_gallery, format_message_with
|
|
34 |
# Import conversation tracker
|
35 |
from conversation_tracker import add_conversation
|
36 |
|
37 |
-
#
|
38 |
-
from api_server import app as api_app
|
39 |
|
40 |
# Import smart warehouse with GPT intelligence and price
|
41 |
try:
|
@@ -1132,9 +1129,56 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storag
|
|
1132 |
yield "", chat_history
|
1133 |
|
1134 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1135 |
|
1136 |
-
#
|
1137 |
-
app = gr.mount_gradio_app(api_app, demo, path="/")
|
1138 |
|
1139 |
if __name__ == "__main__":
|
1140 |
demo.launch(debug=True)
|
|
|
6 |
import schedule
|
7 |
import time
|
8 |
import threading
|
|
|
|
|
9 |
from huggingface_hub import HfApi, create_repo, hf_hub_download
|
10 |
import warnings
|
11 |
import pandas as pd
|
|
|
32 |
# Import conversation tracker
|
33 |
from conversation_tracker import add_conversation
|
34 |
|
35 |
+
# API endpoints removed - will use Gradio's built-in API
|
|
|
36 |
|
37 |
# Import smart warehouse with GPT intelligence and price
|
38 |
try:
|
|
|
1129 |
yield "", chat_history
|
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"""
|
1136 |
+
from conversation_tracker import load_conversations
|
1137 |
+
conversations = load_conversations()
|
1138 |
+
|
1139 |
+
# Format for dashboard
|
1140 |
+
formatted = {}
|
1141 |
+
for conv in conversations:
|
1142 |
+
session_id = f"session_{conv['timestamp'].replace(':', '').replace('-', '').replace('T', '_')[:15]}"
|
1143 |
+
|
1144 |
+
if session_id not in formatted:
|
1145 |
+
formatted[session_id] = {
|
1146 |
+
"customer": "Kullanıcı",
|
1147 |
+
"phone": session_id,
|
1148 |
+
"messages": []
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
formatted[session_id]["messages"].append({
|
1152 |
+
"type": "received",
|
1153 |
+
"text": conv["user"],
|
1154 |
+
"time": conv["timestamp"]
|
1155 |
+
})
|
1156 |
+
|
1157 |
+
formatted[session_id]["messages"].append({
|
1158 |
+
"type": "sent",
|
1159 |
+
"text": conv["bot"],
|
1160 |
+
"time": conv["timestamp"]
|
1161 |
+
})
|
1162 |
+
|
1163 |
+
return formatted
|
1164 |
+
|
1165 |
+
def get_conversation_stats():
|
1166 |
+
"""Get conversation statistics"""
|
1167 |
+
from conversation_tracker import load_conversations
|
1168 |
+
from datetime import datetime
|
1169 |
+
|
1170 |
+
conversations = load_conversations()
|
1171 |
+
today = datetime.now().date()
|
1172 |
+
today_count = sum(1 for conv in conversations
|
1173 |
+
if datetime.fromisoformat(conv["timestamp"]).date() == today)
|
1174 |
+
|
1175 |
+
return {
|
1176 |
+
"total": len(conversations),
|
1177 |
+
"today": today_count,
|
1178 |
+
"active": len(set(conv.get("session_id", i) for i, conv in enumerate(conversations)))
|
1179 |
+
}
|
1180 |
|
1181 |
+
# API will be handled separately in production
|
|
|
1182 |
|
1183 |
if __name__ == "__main__":
|
1184 |
demo.launch(debug=True)
|
requirements.txt
CHANGED
@@ -12,5 +12,3 @@ google-auth-httplib2
|
|
12 |
google-api-python-client
|
13 |
tabulate
|
14 |
Pillow
|
15 |
-
fastapi
|
16 |
-
uvicorn
|
|
|
12 |
google-api-python-client
|
13 |
tabulate
|
14 |
Pillow
|
|
|
|
run_api.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Run API server separately"""
|
2 |
+
|
3 |
+
from api_server import app
|
4 |
+
import uvicorn
|
5 |
+
|
6 |
+
if __name__ == "__main__":
|
7 |
+
# Run on different port to avoid conflict with Gradio
|
8 |
+
uvicorn.run(app, host="0.0.0.0", port=7861)
|