as
Browse files- app.py +29 -8
- requirements.txt +1 -3
app.py
CHANGED
|
@@ -1,18 +1,39 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import uvicorn
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
@app.post("/chat")
|
| 13 |
def chat(msg: Message):
|
| 14 |
-
return {"response": f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# Iniciar
|
| 17 |
-
|
| 18 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import uvicorn
|
| 6 |
+
import threading
|
| 7 |
|
| 8 |
+
# Configurar Streamlit UI
|
| 9 |
+
st.title("Mi Amigo Virtual 馃")
|
| 10 |
+
st.write("Escribe algo para que el bot responda:")
|
| 11 |
|
| 12 |
+
user_input = st.text_input("Tu mensaje:")
|
| 13 |
+
if st.button("Enviar"):
|
| 14 |
+
if user_input:
|
| 15 |
+
response = requests.post(
|
| 16 |
+
"http://localhost:7860/chat",
|
| 17 |
+
json={"text": user_input}
|
| 18 |
+
)
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
st.write("Respuesta:", response.json()["response"])
|
| 21 |
+
else:
|
| 22 |
+
st.write("Error en la respuesta del servidor.")
|
| 23 |
+
|
| 24 |
+
# Crear la API con FastAPI
|
| 25 |
app = FastAPI()
|
| 26 |
|
| 27 |
+
class Message(BaseModel):
|
| 28 |
+
text: str
|
| 29 |
+
|
| 30 |
@app.post("/chat")
|
| 31 |
def chat(msg: Message):
|
| 32 |
+
return {"response": f"Hola! Dijiste: {msg.text}"}
|
| 33 |
+
|
| 34 |
+
# Funci贸n para ejecutar FastAPI en un hilo separado
|
| 35 |
+
def run_api():
|
| 36 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 37 |
|
| 38 |
+
# Iniciar FastAPI en segundo plano
|
| 39 |
+
threading.Thread(target=run_api, daemon=True).start()
|
|
|
requirements.txt
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
transformers
|
| 2 |
torch
|
| 3 |
streamlit
|
| 4 |
-
ffmpeg
|
| 5 |
-
fastapi
|
| 6 |
-
uvicorn
|
|
|
|
| 1 |
transformers
|
| 2 |
torch
|
| 3 |
streamlit
|
| 4 |
+
ffmpeg
|
|
|
|
|
|