Garabatos commited on
Commit
d04b037
1 Parent(s): fb78ab6

sin stream

Browse files
Files changed (1) hide show
  1. app.py +3 -28
app.py CHANGED
@@ -1,15 +1,6 @@
1
- import streamlit as st
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
  import uvicorn
5
- import threading
6
- from fastapi.middleware.wsgi import WSGIMiddleware
7
-
8
- # Crear la aplicaci贸n Streamlit
9
- st.title("Mi Amigo Virtual 馃")
10
-
11
- # Preguntar el nombre del usuario
12
- name = st.text_input("驴Qui茅n eres?")
13
 
14
  # Crear la clase de datos para FastAPI
15
  class Message(BaseModel):
@@ -18,26 +9,10 @@ class Message(BaseModel):
18
  # Crear la aplicaci贸n FastAPI
19
  app = FastAPI()
20
 
21
- # Endpoint de la API para recibir el nombre y responder
22
  @app.post("/chat")
23
  def chat(msg: Message):
24
  return {"response": f"隆Hola {msg.text}! Soy tu amigo virtual. 驴En qu茅 puedo ayudarte hoy?"}
25
 
26
- # Crear la funci贸n que corre FastAPI en segundo plano
27
- def run_api():
28
- uvicorn.run(app, host="0.0.0.0", port=8000)
29
-
30
- # Iniciar FastAPI en un hilo separado
31
- threading.Thread(target=run_api, daemon=True).start()
32
-
33
- # Si el usuario ha ingresado su nombre, se hace la petici贸n a la API
34
- if name:
35
- # Enviar el nombre a la API
36
- import requests
37
- response = requests.post("http://localhost:8000/chat", json={"text": name})
38
-
39
- if response.status_code == 200:
40
- # Mostrar la respuesta de la API
41
- st.write(response.json()["response"])
42
- else:
43
- st.write("隆Hola! 驴C贸mo te llamas?")
 
 
1
  from fastapi import FastAPI
2
  from pydantic import BaseModel
3
  import uvicorn
 
 
 
 
 
 
 
 
4
 
5
  # Crear la clase de datos para FastAPI
6
  class Message(BaseModel):
 
9
  # Crear la aplicaci贸n FastAPI
10
  app = FastAPI()
11
 
 
12
  @app.post("/chat")
13
  def chat(msg: Message):
14
  return {"response": f"隆Hola {msg.text}! Soy tu amigo virtual. 驴En qu茅 puedo ayudarte hoy?"}
15
 
16
+ # Iniciar la API de FastAPI
17
+ if __name__ == "__main__":
18
+ uvicorn.run(app, host="0.0.0.0", port=8000)