Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1005,60 +1005,59 @@ def create_interface():
|
|
| 1005 |
|
| 1006 |
return app
|
| 1007 |
|
| 1008 |
-
# --- API Interface Creation ---
|
| 1009 |
-
def create_api_interface():
|
| 1010 |
-
"""Create a separate API-only interface"""
|
| 1011 |
-
|
| 1012 |
-
api_interface = gr.Interface(
|
| 1013 |
-
fn=run_pipeline_api,
|
| 1014 |
-
inputs=[
|
| 1015 |
-
gr.Textbox(label="DNA Sequence", placeholder="Enter DNA sequence..."),
|
| 1016 |
-
gr.Slider(minimum=50, maximum=99, value=95, label="Similarity Threshold (%)"),
|
| 1017 |
-
gr.Checkbox(label="Build ML Tree", value=False)
|
| 1018 |
-
],
|
| 1019 |
-
outputs=gr.JSON(label="Analysis Results"),
|
| 1020 |
-
title="F Gene Analysis API",
|
| 1021 |
-
description="API endpoint for F gene analysis pipeline",
|
| 1022 |
-
allow_flagging="never"
|
| 1023 |
-
)
|
| 1024 |
-
|
| 1025 |
-
return api_interface
|
| 1026 |
-
|
| 1027 |
# --- Main Application Setup ---
|
| 1028 |
if __name__ == "__main__":
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
|
| 1032 |
-
# Create
|
| 1033 |
-
|
| 1034 |
|
| 1035 |
-
#
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
[
|
| 1041 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1042 |
)
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
|
| 1006 |
return app
|
| 1007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1008 |
# --- Main Application Setup ---
|
| 1009 |
if __name__ == "__main__":
|
| 1010 |
+
import threading
|
| 1011 |
+
import time
|
| 1012 |
|
| 1013 |
+
# Create the main interface (full functionality)
|
| 1014 |
+
main_app = create_interface()
|
| 1015 |
|
| 1016 |
+
# Create a simple API-only interface
|
| 1017 |
+
def create_simple_api():
|
| 1018 |
+
"""Create a minimal API interface that definitely works with enable_api=True"""
|
| 1019 |
+
return gr.Interface(
|
| 1020 |
+
fn=run_pipeline_api,
|
| 1021 |
+
inputs=[
|
| 1022 |
+
"text", # Simple text input
|
| 1023 |
+
gr.Slider(50, 99, 95), # Simple slider
|
| 1024 |
+
"checkbox" # Simple checkbox
|
| 1025 |
+
],
|
| 1026 |
+
outputs="json", # Simple JSON output
|
| 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(2) # Wait for main app to start
|
| 1034 |
+
print("🔌 Starting API server...")
|
| 1035 |
+
|
| 1036 |
+
api_app = create_simple_api()
|
| 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 endpoint: http://localhost:7861/api/predict")
|
| 1048 |
+
|
| 1049 |
+
except Exception as e:
|
| 1050 |
+
print(f"⚠️ API server failed: {e}")
|
| 1051 |
+
|
| 1052 |
+
# Start API server in background
|
| 1053 |
+
api_thread = threading.Thread(target=start_api_server, daemon=True)
|
| 1054 |
+
api_thread.start()
|
| 1055 |
+
|
| 1056 |
+
# Launch main app
|
| 1057 |
+
print("🚀 Starting main application...")
|
| 1058 |
+
main_app.launch(
|
| 1059 |
+
server_name="0.0.0.0",
|
| 1060 |
+
server_port=7860,
|
| 1061 |
+
share=False,
|
| 1062 |
+
show_error=True
|
| 1063 |
+
)
|