Curinha commited on
Commit
75b5466
1 Parent(s): 8f698a6

Enhance home page with Gradio-inspired design and API information

Browse files
Files changed (1) hide show
  1. app.py +61 -28
app.py CHANGED
@@ -20,15 +20,18 @@ app.add_middleware(
20
  allow_headers=["*"],
21
  )
22
 
 
23
  # Define a Pydantic model to handle the input prompt
24
  class AudioRequest(BaseModel):
25
  prompt: str
26
 
 
27
  # Prueba para verificar si la API funciona - la dejamos por ahora para debugging
28
  @app.get("/status")
29
  def status():
30
  return {"status": "API running", "version": "1.0"}
31
 
 
32
  @app.post("/generate-sound/")
33
  async def generate_sound_endpoint(request: AudioRequest):
34
  try:
@@ -49,6 +52,7 @@ async def generate_sound_endpoint(request: AudioRequest):
49
  except Exception as e:
50
  raise HTTPException(status_code=500, detail=str(e))
51
 
 
52
  @app.post("/generate-music/")
53
  async def generate_music_endpoint(request: AudioRequest):
54
  try:
@@ -69,34 +73,63 @@ async def generate_music_endpoint(request: AudioRequest):
69
  except Exception as e:
70
  raise HTTPException(status_code=500, detail=str(e))
71
 
72
- @app.get("/")
 
73
  def home():
74
- """Redirige autom谩ticamente a la documentaci贸n de FastAPI."""
75
- return RedirectResponse(url="/docs")
76
-
77
- with gr.Blocks(
78
- theme=gr.themes.Default(), # Asegurar que se cargue el tema
79
- ) as demo:
80
- gr.Markdown("# 馃幍 API de Sonidos Generativos")
81
- gr.Markdown("Esta interfaz permite interactuar con la API de generaci贸n de sonidos.")
82
- with gr.Tab("Informaci贸n de la API"):
83
- gr.Markdown("""
84
- ## Documentaci贸n completa
85
-
86
- Puedes acceder a la documentaci贸n detallada de la API en:
87
-
88
- - [Documentaci贸n Swagger](/api/docs)
89
- - [Documentaci贸n ReDoc](/api/redoc)
90
-
91
- ## Endpoints disponibles
92
-
93
- - `GET /api/health` - Verificar el estado del servicio
94
- - `POST /api/generate-sound` - Generar sonido a partir de descripci贸n
95
- - `POST /api/generate-music` - Generar m煤sica a partir de descripci贸n
96
- """)
97
-
98
- # Montar FastAPI dentro de Gradio
99
- app = gr.mount_gradio_app(app, demo, path="/gradio")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  if __name__ == "__main__":
102
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
20
  allow_headers=["*"],
21
  )
22
 
23
+
24
  # Define a Pydantic model to handle the input prompt
25
  class AudioRequest(BaseModel):
26
  prompt: str
27
 
28
+
29
  # Prueba para verificar si la API funciona - la dejamos por ahora para debugging
30
  @app.get("/status")
31
  def status():
32
  return {"status": "API running", "version": "1.0"}
33
 
34
+
35
  @app.post("/generate-sound/")
36
  async def generate_sound_endpoint(request: AudioRequest):
37
  try:
 
52
  except Exception as e:
53
  raise HTTPException(status_code=500, detail=str(e))
54
 
55
+
56
  @app.post("/generate-music/")
57
  async def generate_music_endpoint(request: AudioRequest):
58
  try:
 
73
  except Exception as e:
74
  raise HTTPException(status_code=500, detail=str(e))
75
 
76
+
77
+ @app.get("/", response_class=HTMLResponse)
78
  def home():
79
+ """P谩gina de inicio con informaci贸n de la API y estilo inspirado en Gradio."""
80
+ return """
81
+ <html>
82
+ <head>
83
+ <title>API de Sonidos Generativos</title>
84
+ <style>
85
+ body {
86
+ font-family: Arial, sans-serif;
87
+ background-color: #0B0F19;
88
+ color: white;
89
+ text-align: center;
90
+ padding: 50px;
91
+ }
92
+ h1 {
93
+ color: #FFFFFF;
94
+ }
95
+ a {
96
+ color: #FFCC00;
97
+ text-decoration: none;
98
+ font-size: 18px;
99
+ }
100
+ .container {
101
+ background: #1B1E29;
102
+ padding: 20px;
103
+ border-radius: 10px;
104
+ display: inline-block;
105
+ margin-top: 20px;
106
+ }
107
+ .button {
108
+ background-color: #FFCC00;
109
+ color: black;
110
+ padding: 10px 20px;
111
+ margin-top: 15px;
112
+ display: inline-block;
113
+ border-radius: 5px;
114
+ }
115
+ .button:hover {
116
+ background-color: #E6B800;
117
+ }
118
+ </style>
119
+ </head>
120
+ <body>
121
+ <h1>API de Sonidos Generativos</h1>
122
+ <p>Esta API ofrece tres endpoints:</p>
123
+ <div class="container">
124
+ <p>馃搫 <a href="/docs">/docs</a> - Documentaci贸n interactiva</p>
125
+ <p>馃幍 <a href="/generate-music">/generate-music</a> - Genera m煤sica basada en un prompt</p>
126
+ <p>馃攰 <a href="/generate-sound">/generate-sound</a> - Genera sonidos a partir de una descripci贸n</p>
127
+ <a class="button" href="https://paginaexterna.com/test-api" target="_blank">馃敆 Probar en nuestra web</a>
128
+ </div>
129
+ </body>
130
+ </html>
131
+ """
132
+
133
 
134
  if __name__ == "__main__":
135
+ uvicorn.run(app, host="0.0.0.0", port=7860)