davidegato1 commited on
Commit
5be0243
·
verified ·
1 Parent(s): e1f9112

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -32,7 +32,7 @@ def download_bing_images(search_query, limit, adult_filter_off):
32
  print(f"Erreur Bing : {str(e)}")
33
  return []
34
 
35
- # Téléchargement via Google (méthode sécurisée)
36
  def download_google_images(search_query, limit):
37
  try:
38
  output_dir = os.path.join('dataset', f'google_{search_query}')
@@ -85,21 +85,17 @@ def get_image_paths(directory):
85
 
86
  # Fonction principale appelée par l'interface Gradio
87
  def download_handler(source, query, limit, safe_mode):
88
- # S'assurer que le nombre d'images est entre 1 et 100
89
  limit = max(1, min(limit, 100))
90
  try:
91
  if source == "Bing":
92
- # Si safe_mode est "Off", alors le filtre est désactivé (adult_filter_off=True)
93
  image_paths = download_bing_images(query, limit, safe_mode == "Off")
94
  elif source == "Google":
95
  image_paths = download_google_images(query, limit)
96
  else:
97
  image_paths = []
98
 
99
- if image_paths:
100
- status_msg = f"{len(image_paths)} image(s) téléchargée(s)."
101
- else:
102
- status_msg = "Aucune image téléchargée."
103
  return image_paths, status_msg
104
  except Exception as e:
105
  print(f"Erreur globale : {str(e)}")
@@ -121,7 +117,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Image Downloader") as app:
121
  gallery = gr.Gallery(label="Résultats", columns=5, object_fit="contain", height="auto")
122
  status = gr.Textbox(label="Statut", interactive=False)
123
 
124
- # Liaison du bouton au gestionnaire de téléchargement (2 sorties attendues)
125
  submit_btn.click(
126
  fn=download_handler,
127
  inputs=[source, query, limit, safe_mode],
@@ -138,5 +133,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Image Downloader") as app:
138
  )
139
 
140
  if __name__ == "__main__":
141
- # Utilisation de server_name="0.0.0.0" pour Hugging Face Spaces
142
- app.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
 
 
 
32
  print(f"Erreur Bing : {str(e)}")
33
  return []
34
 
35
+ # Téléchargement via Google
36
  def download_google_images(search_query, limit):
37
  try:
38
  output_dir = os.path.join('dataset', f'google_{search_query}')
 
85
 
86
  # Fonction principale appelée par l'interface Gradio
87
  def download_handler(source, query, limit, safe_mode):
 
88
  limit = max(1, min(limit, 100))
89
  try:
90
  if source == "Bing":
91
+ # Si safe_mode est "Off", le filtre est désactivé (adult_filter_off=True)
92
  image_paths = download_bing_images(query, limit, safe_mode == "Off")
93
  elif source == "Google":
94
  image_paths = download_google_images(query, limit)
95
  else:
96
  image_paths = []
97
 
98
+ status_msg = f"{len(image_paths)} image(s) téléchargée(s)." if image_paths else "Aucune image téléchargée."
 
 
 
99
  return image_paths, status_msg
100
  except Exception as e:
101
  print(f"Erreur globale : {str(e)}")
 
117
  gallery = gr.Gallery(label="Résultats", columns=5, object_fit="contain", height="auto")
118
  status = gr.Textbox(label="Statut", interactive=False)
119
 
 
120
  submit_btn.click(
121
  fn=download_handler,
122
  inputs=[source, query, limit, safe_mode],
 
133
  )
134
 
135
  if __name__ == "__main__":
136
+ # Récupère le port depuis la variable d'environnement (nécessaire pour Hugging Face Spaces)
137
+ port = int(os.environ.get("PORT", 7860))
138
+ app.launch(server_name="0.0.0.0", server_port=port, show_error=True)
139
+