Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1005,6 +1005,7 @@ def create_interface():
|
|
| 1005 |
|
| 1006 |
return app
|
| 1007 |
|
|
|
|
| 1008 |
# --- Main Application Setup ---
|
| 1009 |
if __name__ == "__main__":
|
| 1010 |
import threading
|
|
@@ -1013,51 +1014,55 @@ if __name__ == "__main__":
|
|
| 1013 |
# Create the main interface (full functionality)
|
| 1014 |
main_app = create_interface()
|
| 1015 |
|
| 1016 |
-
# Create a simple API-only interface
|
| 1017 |
-
def
|
| 1018 |
-
"""Create
|
| 1019 |
return gr.Interface(
|
| 1020 |
fn=run_pipeline_api,
|
| 1021 |
inputs=[
|
| 1022 |
-
"
|
| 1023 |
-
gr.Slider(50, 99, 95
|
| 1024 |
-
"
|
| 1025 |
],
|
| 1026 |
-
outputs="
|
| 1027 |
-
title="F Gene Analysis API"
|
|
|
|
| 1028 |
)
|
| 1029 |
|
| 1030 |
def start_api_server():
|
| 1031 |
-
"""Start API server in background thread"""
|
| 1032 |
try:
|
| 1033 |
-
time.sleep(
|
| 1034 |
print("🔌 Starting API server...")
|
| 1035 |
|
| 1036 |
-
|
|
|
|
|
|
|
|
|
|
| 1037 |
api_app.launch(
|
| 1038 |
server_name="0.0.0.0",
|
| 1039 |
server_port=7861,
|
| 1040 |
-
enable_api=True,
|
| 1041 |
-
api_open=True,
|
| 1042 |
share=False,
|
| 1043 |
prevent_thread_lock=True,
|
| 1044 |
-
quiet=True
|
|
|
|
| 1045 |
)
|
| 1046 |
print("✅ API server running on http://localhost:7861")
|
| 1047 |
-
print("📡 API
|
| 1048 |
|
| 1049 |
except Exception as e:
|
| 1050 |
print(f"⚠️ API server failed: {e}")
|
|
|
|
|
|
|
| 1051 |
|
| 1052 |
-
#
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
)
|
|
|
|
| 1005 |
|
| 1006 |
return app
|
| 1007 |
|
| 1008 |
+
# --- Main Application Setup ---
|
| 1009 |
# --- Main Application Setup ---
|
| 1010 |
if __name__ == "__main__":
|
| 1011 |
import threading
|
|
|
|
| 1014 |
# Create the main interface (full functionality)
|
| 1015 |
main_app = create_interface()
|
| 1016 |
|
| 1017 |
+
# Create a simple API-only interface for API functionality
|
| 1018 |
+
def create_api_interface():
|
| 1019 |
+
"""Create API interface using the newer Gradio API approach"""
|
| 1020 |
return gr.Interface(
|
| 1021 |
fn=run_pipeline_api,
|
| 1022 |
inputs=[
|
| 1023 |
+
gr.Textbox(label="DNA Sequence", placeholder="Enter DNA sequence..."),
|
| 1024 |
+
gr.Slider(minimum=50, maximum=99, value=95, label="Similarity Threshold (%)"),
|
| 1025 |
+
gr.Checkbox(label="Build ML Tree", value=False)
|
| 1026 |
],
|
| 1027 |
+
outputs=gr.JSON(label="Analysis Results"),
|
| 1028 |
+
title="F Gene Analysis API",
|
| 1029 |
+
description="API endpoint for F gene analysis pipeline"
|
| 1030 |
)
|
| 1031 |
|
| 1032 |
def start_api_server():
|
| 1033 |
+
"""Start API server in background thread using newer Gradio approach"""
|
| 1034 |
try:
|
| 1035 |
+
time.sleep(3) # Wait for main app to start
|
| 1036 |
print("🔌 Starting API server...")
|
| 1037 |
|
| 1038 |
+
# Create API interface
|
| 1039 |
+
api_app = create_api_interface()
|
| 1040 |
+
|
| 1041 |
+
# Launch API server - remove enable_api parameter
|
| 1042 |
api_app.launch(
|
| 1043 |
server_name="0.0.0.0",
|
| 1044 |
server_port=7861,
|
|
|
|
|
|
|
| 1045 |
share=False,
|
| 1046 |
prevent_thread_lock=True,
|
| 1047 |
+
quiet=True,
|
| 1048 |
+
show_error=True
|
| 1049 |
)
|
| 1050 |
print("✅ API server running on http://localhost:7861")
|
| 1051 |
+
print("📡 API available at: http://localhost:7861")
|
| 1052 |
|
| 1053 |
except Exception as e:
|
| 1054 |
print(f"⚠️ API server failed: {e}")
|
| 1055 |
+
import traceback
|
| 1056 |
+
print(f"Full error: {traceback.format_exc()}")
|
| 1057 |
|
| 1058 |
+
# Method 1: Single app with both web UI and API capabilities
|
| 1059 |
+
try:
|
| 1060 |
+
print("🚀 Starting main application with integrated API...")
|
| 1061 |
+
main_app.launch(
|
| 1062 |
+
server_name="0.0.0.0",
|
| 1063 |
+
server_port=7860,
|
| 1064 |
+
share=False,
|
| 1065 |
+
show_error=True,
|
| 1066 |
+
# API is automatically available in newer Gradio versions
|
| 1067 |
+
# Access via: http://localhost:7860/api/predict
|
| 1068 |
+
)
|
|
|