Harshit0414 commited on
Commit
d5b9d5e
·
verified ·
1 Parent(s): 0ab9c2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -19,10 +19,18 @@ if not HF_TOKEN:
19
 
20
  # Initialize backend client
21
  try:
22
- backend_client = Client(BACKEND_URL, hf_token=HF_TOKEN)
 
 
 
 
 
 
 
23
  print(f"Connected to backend at {BACKEND_URL}")
24
  except Exception as e:
25
  print(f"Warning: Could not connect to backend: {e}")
 
26
  backend_client = None
27
 
28
  def add_sentences_ui(sentences_text):
@@ -238,5 +246,7 @@ with gr.Blocks(title="RAM-P - Interactive Learning") as frontend_app:
238
  """)
239
 
240
  if __name__ == "__main__":
241
- frontend_app.launch(server_name="0.0.0.0", server_port=7861)
 
 
242
 
 
19
 
20
  # Initialize backend client
21
  try:
22
+ # For private Spaces, pass token via headers or use HF_TOKEN environment variable
23
+ # Gradio Client automatically uses HF_TOKEN env var if available
24
+ if HF_TOKEN:
25
+ # Set as environment variable for gradio-client to pick up
26
+ os.environ["HF_TOKEN"] = HF_TOKEN
27
+ backend_client = Client(BACKEND_URL)
28
+ else:
29
+ backend_client = Client(BACKEND_URL)
30
  print(f"Connected to backend at {BACKEND_URL}")
31
  except Exception as e:
32
  print(f"Warning: Could not connect to backend: {e}")
33
+ print(f"Make sure BACKEND_URL and HF_TOKEN are set correctly.")
34
  backend_client = None
35
 
36
  def add_sentences_ui(sentences_text):
 
246
  """)
247
 
248
  if __name__ == "__main__":
249
+ # Let Gradio use default port (7860) or GRADIO_SERVER_PORT env var
250
+ # Don't hardcode port - let Hugging Face Spaces handle it
251
+ frontend_app.launch()
252