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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -27
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 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
- )
 
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
+ )