ancerlop commited on
Commit
bd4e55e
verified
1 Parent(s): 4c22a32

Fix Gradio Error

Browse files

I've updated the`backend/app.py` file to fix the runtime error you encountered. The issue was caused by using an incorrect Gradio function (`mount_gradio_app` ) to integrate the Flask API. I replaced it with the appropriate method (`mount_wsgi_app` within a Gradio`Blocks` structure), which should now allow the application to run correctly, especially in environments like Hugging Face Spaces.

Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -166,11 +166,22 @@ iface = gr.Interface(
166
  allow_flagging='never'
167
  )
168
 
169
- # Montar la interfaz Gradio en la app Flask en la ruta ra铆z
170
- app = gr.mount_gradio_app(app, iface, path="/")
 
 
 
 
 
 
 
 
171
 
172
  # --- Ejecuci贸n de la App ---
173
 
174
  if __name__ == '__main__':
175
- port = int(os.environ.get('PORT', 5000))
176
- app.run(host='0.0.0.0', port=port)
 
 
 
 
166
  allow_flagging='never'
167
  )
168
 
169
+ # --- Integration and Execution ---
170
+
171
+ # Create a main Gradio Blocks app to host both the UI and the API
172
+ with gr.Blocks(title="馃強u200d鈾傦笍 42CodeRunner") as demo:
173
+ # Render the defined interface within the Blocks
174
+ iface.render()
175
+
176
+ # Mount the Flask app (containing the API) onto the Gradio Blocks app under /api
177
+ # This makes the Flask routes available at paths like /api/execute
178
+ demo = gr.mount_wsgi_app(demo, app, path="/api")
179
 
180
  # --- Ejecuci贸n de la App ---
181
 
182
  if __name__ == '__main__':
183
+ # Use Gradio's default port or environment variable
184
+ port = int(os.environ.get('PORT', 7860))
185
+ # Launch the combined Gradio Blocks app
186
+ # Allow connection from network (needed for Docker/Spaces)
187
+ demo.launch(server_name='0.0.0.0', server_port=port)