Spaces:
Sleeping
Sleeping
Commit
路
bd7a9bc
1
Parent(s):
d15755e
app.py
CHANGED
|
@@ -2,22 +2,6 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import logging
|
| 4 |
import os
|
| 5 |
-
from fastapi import FastAPI, Request
|
| 6 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
-
import uvicorn
|
| 8 |
-
from multiprocessing import Process
|
| 9 |
-
|
| 10 |
-
# Crear la aplicaci贸n FastAPI
|
| 11 |
-
app = FastAPI()
|
| 12 |
-
|
| 13 |
-
# Configurar CORS si es necesario
|
| 14 |
-
app.add_middleware(
|
| 15 |
-
CORSMiddleware,
|
| 16 |
-
allow_origins=["*"], # Ajusta esto seg煤n tus necesidades
|
| 17 |
-
allow_credentials=True,
|
| 18 |
-
allow_methods=["*"],
|
| 19 |
-
allow_headers=["*"],
|
| 20 |
-
)
|
| 21 |
|
| 22 |
# Leer el token de Hugging Face desde las variables de entorno
|
| 23 |
HUGGING_FACE_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
|
|
@@ -97,30 +81,6 @@ def predict(message, history):
|
|
| 97 |
else:
|
| 98 |
return "No se pudo mejorar la resoluci贸n."
|
| 99 |
|
| 100 |
-
#
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
data = await request.json()
|
| 104 |
-
message = data.get("message")
|
| 105 |
-
response = predict(message, [])
|
| 106 |
-
return {"response": response}
|
| 107 |
-
|
| 108 |
-
# Funci贸n para ejecutar Gradio
|
| 109 |
-
def run_gradio():
|
| 110 |
-
iface = gr.ChatInterface(predict)
|
| 111 |
-
iface.launch(share=True)
|
| 112 |
-
|
| 113 |
-
# Funci贸n para ejecutar FastAPI con uvicorn
|
| 114 |
-
def run_fastapi():
|
| 115 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 116 |
-
|
| 117 |
-
# Ejecutar Gradio y FastAPI en procesos separados
|
| 118 |
-
if __name__ == "__main__":
|
| 119 |
-
gradio_process = Process(target=run_gradio)
|
| 120 |
-
fastapi_process = Process(target=run_fastapi)
|
| 121 |
-
|
| 122 |
-
gradio_process.start()
|
| 123 |
-
fastapi_process.start()
|
| 124 |
-
|
| 125 |
-
gradio_process.join()
|
| 126 |
-
fastapi_process.join()
|
|
|
|
| 2 |
import requests
|
| 3 |
import logging
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Leer el token de Hugging Face desde las variables de entorno
|
| 7 |
HUGGING_FACE_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
|
|
|
|
| 81 |
else:
|
| 82 |
return "No se pudo mejorar la resoluci贸n."
|
| 83 |
|
| 84 |
+
# Crear y lanzar la interfaz de Gradio con un enlace p煤blico
|
| 85 |
+
iface = gr.ChatInterface(predict)
|
| 86 |
+
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|