Dax451 commited on
Commit
2cd32af
·
1 Parent(s): 36e919a

Ottimizzata la configurazione per rilevare automaticamente l'ambiente Hugging Face Spaces

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -277,19 +277,33 @@ def main():
277
  username = os.getenv("GRADIO_USERNAME")
278
  password = os.getenv("GRADIO_PASSWORD")
279
 
280
- # Configura l'autenticazione per Gradio 5.x
 
 
 
281
  if username and password:
282
  print(f"Autenticazione configurata con username: {username}")
283
- # In Gradio 5.x, l'autenticazione è una lista di tuple
284
- interface.launch(
285
- server_name="0.0.0.0",
286
- auth=[(username, password)],
287
- share=True # Necessario per Hugging Face Spaces
288
- )
 
 
 
 
 
289
  else:
290
  # Per test locali, disabilitiamo l'autenticazione
291
  print("Autenticazione disabilitata per test locali. Su HF Spaces, imposta GRADIO_USERNAME e GRADIO_PASSWORD.")
292
- interface.launch(server_name="0.0.0.0", share=True)
 
 
 
 
 
 
293
 
294
  if __name__ == "__main__":
295
  main()
 
277
  username = os.getenv("GRADIO_USERNAME")
278
  password = os.getenv("GRADIO_PASSWORD")
279
 
280
+ # Determina se siamo in Hugging Face Spaces
281
+ is_huggingface_space = os.getenv("SPACE_ID") is not None
282
+
283
+ # Configura l'autenticazione
284
  if username and password:
285
  print(f"Autenticazione configurata con username: {username}")
286
+ # Configurazione specifica in base all'ambiente
287
+ launch_kwargs = {
288
+ "server_name": "0.0.0.0",
289
+ "auth": [(username, password)]
290
+ }
291
+
292
+ # Share è necessario solo quando non siamo su HF Spaces
293
+ if not is_huggingface_space:
294
+ launch_kwargs["share"] = True
295
+
296
+ interface.launch(**launch_kwargs)
297
  else:
298
  # Per test locali, disabilitiamo l'autenticazione
299
  print("Autenticazione disabilitata per test locali. Su HF Spaces, imposta GRADIO_USERNAME e GRADIO_PASSWORD.")
300
+
301
+ # Configurazione per testing locale
302
+ launch_kwargs = {"server_name": "0.0.0.0"}
303
+ if not is_huggingface_space:
304
+ launch_kwargs["share"] = True
305
+
306
+ interface.launch(**launch_kwargs)
307
 
308
  if __name__ == "__main__":
309
  main()