Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
-
from pydantic import BaseModel
|
| 4 |
-
import os
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
-
|
| 7 |
-
load_dotenv()
|
| 8 |
-
|
| 9 |
-
app = FastAPI(title="Guy+22656888879 Chatbot API")
|
| 10 |
-
|
| 11 |
-
app.add_middleware(
|
| 12 |
-
CORSMiddleware,
|
| 13 |
-
allow_origins=[
|
| 14 |
-
"https://huggyguyjo01-testdashbord.static.hf.space",
|
| 15 |
-
"https://huggyguyjo01-testchat.static.hf.space"
|
| 16 |
-
],
|
| 17 |
-
allow_credentials=True,
|
| 18 |
-
allow_methods=["*"],
|
| 19 |
-
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
response = f"Message reçu de {message.user_id}: {message.text}"
|
| 30 |
-
return {"status": "success", "response": response}
|
| 31 |
-
except Exception as e:
|
| 32 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 33 |
-
|
| 34 |
-
@app.websocket("/ws")
|
| 35 |
-
async def websocket_endpoint(websocket: WebSocket):
|
| 36 |
-
await websocket.accept()
|
| 37 |
-
try:
|
| 38 |
-
while True:
|
| 39 |
-
data = await websocket.receive_text()
|
| 40 |
-
response = f"Message reçu: {data}"
|
| 41 |
-
await websocket.send_text(response)
|
| 42 |
-
except Exception as e:
|
| 43 |
-
await websocket.close(code=1000)
|
|
|
|
| 1 |
+
connecting dashboard and chat interface"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
)
|
| 3 |
|
| 4 |
+
# Launch the interface
|
| 5 |
+
if __name__ == "__main__":
|
| 6 |
+
iface.launch(
|
| 7 |
+
server_name="0.0.0.0",
|
| 8 |
+
server_port=7860,
|
| 9 |
+
share=True
|
| 10 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|