Spaces:
Running
Running
Curinha
commited on
Commit
路
fa56145
1
Parent(s):
a9c5018
Refactor app.py to use Jinja2 templates for the home page and update API metadata
Browse files- app.py +17 -58
- templates/home.html +53 -0
app.py
CHANGED
|
@@ -1,15 +1,24 @@
|
|
| 1 |
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
import uvicorn
|
| 4 |
|
| 5 |
from sound_generator import generate_sound, generate_music
|
| 6 |
-
from fastapi import FastAPI, HTTPException
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
-
from fastapi.
|
|
|
|
| 9 |
from pydantic import BaseModel
|
| 10 |
|
| 11 |
# Create the FastAPI app with custom docs URL
|
| 12 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Configuraci贸n de CORS
|
| 15 |
app.add_middleware(
|
|
@@ -76,60 +85,10 @@ async def generate_music_endpoint(request: AudioRequest):
|
|
| 76 |
|
| 77 |
|
| 78 |
@app.get("/", response_class=HTMLResponse)
|
| 79 |
-
def home():
|
| 80 |
-
"""P谩gina de inicio con informaci贸n de la API
|
| 81 |
-
return """
|
| 82 |
-
|
| 83 |
-
<head>
|
| 84 |
-
<title>API de Sonidos Generativos</title>
|
| 85 |
-
<style>
|
| 86 |
-
body {
|
| 87 |
-
font-family: Arial, sans-serif;
|
| 88 |
-
background-color: #0B0F19;
|
| 89 |
-
color: white;
|
| 90 |
-
text-align: center;
|
| 91 |
-
padding: 50px;
|
| 92 |
-
}
|
| 93 |
-
h1 {
|
| 94 |
-
color: #FFFFFF;
|
| 95 |
-
}
|
| 96 |
-
a {
|
| 97 |
-
color: #FFCC00;
|
| 98 |
-
text-decoration: none;
|
| 99 |
-
font-size: 18px;
|
| 100 |
-
}
|
| 101 |
-
.container {
|
| 102 |
-
background: #1B1E29;
|
| 103 |
-
padding: 20px;
|
| 104 |
-
border-radius: 10px;
|
| 105 |
-
display: inline-block;
|
| 106 |
-
margin-top: 20px;
|
| 107 |
-
}
|
| 108 |
-
.button {
|
| 109 |
-
background-color: #FFCC00;
|
| 110 |
-
color: black;
|
| 111 |
-
padding: 10px 20px;
|
| 112 |
-
margin-top: 15px;
|
| 113 |
-
display: inline-block;
|
| 114 |
-
border-radius: 5px;
|
| 115 |
-
}
|
| 116 |
-
.button:hover {
|
| 117 |
-
background-color: #E6B800;
|
| 118 |
-
}
|
| 119 |
-
</style>
|
| 120 |
-
</head>
|
| 121 |
-
<body>
|
| 122 |
-
<h1>API de Sonidos Generativos</h1>
|
| 123 |
-
<p>Esta API ofrece tres endpoints:</p>
|
| 124 |
-
<div class="container">
|
| 125 |
-
<p>馃搫 <a href="/docs">/docs</a> - Documentaci贸n interactiva</p>
|
| 126 |
-
<p>馃幍 <a href="/generate-music">/generate-music</a> - Genera m煤sica basada en un prompt</p>
|
| 127 |
-
<p>馃攰 <a href="/generate-sound">/generate-sound</a> - Genera sonidos a partir de una descripci贸n</p>
|
| 128 |
-
<a class="button" href="https://paginaexterna.com/test-api" target="_blank">馃敆 Probar en nuestra web</a>
|
| 129 |
-
</div>
|
| 130 |
-
</body>
|
| 131 |
-
</html>
|
| 132 |
-
"""
|
| 133 |
|
| 134 |
if __name__ == "__main__":
|
| 135 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import uvicorn
|
| 3 |
|
| 4 |
from sound_generator import generate_sound, generate_music
|
| 5 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
+
from fastapi.templating import Jinja2Templates
|
| 8 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 9 |
from pydantic import BaseModel
|
| 10 |
|
| 11 |
# Create the FastAPI app with custom docs URL
|
| 12 |
+
app = FastAPI(
|
| 13 |
+
title="API de Sonidos Generativos",
|
| 14 |
+
description="API para generar sonidos y m煤sica basados en prompts",
|
| 15 |
+
version="1.0.0",
|
| 16 |
+
docs_url="/docs",
|
| 17 |
+
redoc_url="/redoc",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Cargar las plantillas desde la carpeta "templates"
|
| 21 |
+
templates = Jinja2Templates(directory="templates")
|
| 22 |
|
| 23 |
# Configuraci贸n de CORS
|
| 24 |
app.add_middleware(
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
@app.get("/", response_class=HTMLResponse)
|
| 88 |
+
def home(request: Request):
|
| 89 |
+
"""P谩gina de inicio con informaci贸n de la API"""
|
| 90 |
+
return templates.TemplateResponse("home.html", {"request": request})
|
| 91 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
templates/home.html
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="es">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>API de Sonidos Generativos</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
background-color: #0B0F19;
|
| 11 |
+
color: white;
|
| 12 |
+
text-align: center;
|
| 13 |
+
padding: 50px;
|
| 14 |
+
}
|
| 15 |
+
h1 {
|
| 16 |
+
color: #FFFFFF;
|
| 17 |
+
}
|
| 18 |
+
a {
|
| 19 |
+
color: #FFCC00;
|
| 20 |
+
text-decoration: none;
|
| 21 |
+
font-size: 18px;
|
| 22 |
+
}
|
| 23 |
+
.container {
|
| 24 |
+
background: #1B1E29;
|
| 25 |
+
padding: 20px;
|
| 26 |
+
border-radius: 10px;
|
| 27 |
+
display: inline-block;
|
| 28 |
+
margin-top: 20px;
|
| 29 |
+
}
|
| 30 |
+
.button {
|
| 31 |
+
background-color: #FFCC00;
|
| 32 |
+
color: black;
|
| 33 |
+
padding: 10px 20px;
|
| 34 |
+
margin-top: 15px;
|
| 35 |
+
display: inline-block;
|
| 36 |
+
border-radius: 5px;
|
| 37 |
+
}
|
| 38 |
+
.button:hover {
|
| 39 |
+
background-color: #E6B800;
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
</head>
|
| 43 |
+
<body>
|
| 44 |
+
<h1>API de Sonidos Generativos</h1>
|
| 45 |
+
<p>Esta API ofrece tres endpoints:</p>
|
| 46 |
+
<div class="container">
|
| 47 |
+
<p>馃搫 <a href="/docs">/docs</a> - Documentaci贸n interactiva</p>
|
| 48 |
+
<p>馃幍 <a href="/generate-music">/generate-music</a> - Genera m煤sica basada en un prompt</p>
|
| 49 |
+
<p>馃攰 <a href="/generate-sound">/generate-sound</a> - Genera sonidos a partir de una descripci贸n</p>
|
| 50 |
+
<a class="button" href="https://paginaexterna.com/test-api" target="_blank">馃敆 Probar en nuestra web</a>
|
| 51 |
+
</div>
|
| 52 |
+
</body>
|
| 53 |
+
</html>
|