re-type commited on
Commit
38fd28f
·
verified ·
1 Parent(s): 283c356

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -52
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
- # Create the main interface
1030
- main_app = create_interface()
1031
 
1032
- # Create API interface
1033
- api_app = create_api_interface()
1034
 
1035
- # Try to launch with API enabled
1036
- try:
1037
- # Mount both interfaces
1038
- app = gr.TabbedInterface(
1039
- [main_app, api_app],
1040
- ["Main Interface", "API"],
1041
- title="F Gene Analysis Pipeline"
 
 
 
 
 
1042
  )
1043
-
1044
- # Launch with API enabled
1045
- app.launch(
1046
- server_name="0.0.0.0",
1047
- server_port=7860,
1048
- share=False,
1049
- enable_api=True, # This should work now
1050
- api_open=True,
1051
- show_error=True
1052
- )
1053
-
1054
- except Exception as e:
1055
- logging.error(f"Failed to launch with API: {e}")
1056
- logging.info("Falling back to main interface without API...")
1057
-
1058
- # Fallback: launch main interface without API
1059
- main_app.launch(
1060
- server_name="0.0.0.0",
1061
- server_port=7860,
1062
- share=False,
1063
- show_error=True
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
+ )