Spaces:
Running
Running
Dax451
commited on
Commit
·
7f876c1
1
Parent(s):
2cd32af
Implementata funzione di autenticazione e configurazione ottimizzata per Hugging Face Spaces
Browse files
app.py
CHANGED
|
@@ -277,33 +277,27 @@ def main():
|
|
| 277 |
username = os.getenv("GRADIO_USERNAME")
|
| 278 |
password = os.getenv("GRADIO_PASSWORD")
|
| 279 |
|
| 280 |
-
#
|
| 281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
# Configura l'autenticazione
|
| 284 |
if username and password:
|
| 285 |
print(f"Autenticazione configurata con username: {username}")
|
| 286 |
-
|
| 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 |
-
|
| 302 |
-
|
| 303 |
-
if not is_huggingface_space:
|
| 304 |
-
launch_kwargs["share"] = True
|
| 305 |
-
|
| 306 |
-
interface.launch(**launch_kwargs)
|
| 307 |
|
| 308 |
if __name__ == "__main__":
|
| 309 |
main()
|
|
|
|
| 277 |
username = os.getenv("GRADIO_USERNAME")
|
| 278 |
password = os.getenv("GRADIO_PASSWORD")
|
| 279 |
|
| 280 |
+
# Funzione di autenticazione
|
| 281 |
+
def auth_function(user, pwd):
|
| 282 |
+
return user == username and pwd == password
|
| 283 |
+
|
| 284 |
+
# Parametri di lancio
|
| 285 |
+
launch_kwargs = {
|
| 286 |
+
"server_name": "0.0.0.0",
|
| 287 |
+
"share": True, # Sempre necessario per HF Spaces
|
| 288 |
+
"ssr": False # Disabilita SSR sperimentale
|
| 289 |
+
}
|
| 290 |
|
| 291 |
# Configura l'autenticazione
|
| 292 |
if username and password:
|
| 293 |
print(f"Autenticazione configurata con username: {username}")
|
| 294 |
+
launch_kwargs["auth"] = auth_function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
else:
|
| 296 |
# Per test locali, disabilitiamo l'autenticazione
|
| 297 |
print("Autenticazione disabilitata per test locali. Su HF Spaces, imposta GRADIO_USERNAME e GRADIO_PASSWORD.")
|
| 298 |
+
|
| 299 |
+
# Avvia l'interfaccia
|
| 300 |
+
interface.launch(**launch_kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
if __name__ == "__main__":
|
| 303 |
main()
|