Curinha commited on
Commit
232bd64
1 Parent(s): 525c0ee

Integrate Gradio interface and simplify root endpoint handling

Browse files
Files changed (1) hide show
  1. app.py +3 -40
app.py CHANGED
@@ -69,44 +69,7 @@ async def generate_music_endpoint(request: AudioRequest):
69
  except Exception as e:
70
  raise HTTPException(status_code=500, detail=str(e))
71
 
 
 
72
 
73
- @app.get("/")
74
- def root():
75
- return RedirectResponse(url="/gradio")
76
-
77
-
78
- # Interfaz con Gradio (solo documentaci贸n)
79
- def gradio_ui():
80
- description = """
81
- # API de Generaci贸n de Texto
82
- Esta API utiliza `GPT-2` para generar texto basado en un prompt.
83
-
84
- ## Uso:
85
- 1. Visita [la documentaci贸n interactiva](https://<TU-HF-SPACE>.hf.space/docs) para probar la API.
86
- 2. Endpoint principal: `GET /generate?prompt=TuTexto`
87
- 3. Par谩metros:
88
- - `prompt` (str): Texto inicial.
89
- - `max_length` (int, opcional): Longitud m谩xima del texto generado.
90
-
91
- 馃搶 **Ejemplo de llamada en Python:**
92
- ```python
93
- import requests
94
- url = "https://<TU-HF-SPACE>.hf.space/generate?prompt=Hola"
95
- response = requests.get(url)
96
- print(response.json())
97
- ```
98
- """
99
- return gr.Markdown(description)
100
-
101
- gr_app = gr.Blocks()
102
- with gr_app:
103
- gradio_ui()
104
-
105
- @app.get("/gradio")
106
- def gradio_launch():
107
- """Lanza la interfaz de Gradio"""
108
- return gr_app.launch(server_name="0.0.0.0", server_port=7860, inline=False, share=False)
109
-
110
- # Para ejecutar en local
111
- if __name__ == "__main__":
112
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
69
  except Exception as e:
70
  raise HTTPException(status_code=500, detail=str(e))
71
 
72
+ io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
73
+ gradio_app = gr.routes.App.create_app(io)
74
 
75
+ app.mount("/", gradio_app)