Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from flowise import Flowise
|
| 5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -19,30 +22,7 @@ if FLOWISE_HOST and FLOWISE_API_KEY and CHATFLOW_ID:
|
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Error initializing Flowise: {e}")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
status_code=500,
|
| 27 |
-
content={"error": "Flowise not initialized. Check environment variables."}
|
| 28 |
-
)
|
| 29 |
-
try:
|
| 30 |
-
data = await request.json()
|
| 31 |
-
user_message = data.get("message", "")
|
| 32 |
-
if not user_message:
|
| 33 |
-
return JSONResponse(
|
| 34 |
-
status_code=400,
|
| 35 |
-
content={"error": "Message is required"}
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
response = flowise.chat(user_message)
|
| 39 |
-
return {"response": response}
|
| 40 |
-
except Exception as e:
|
| 41 |
-
return JSONResponse(
|
| 42 |
-
status_code=500,
|
| 43 |
-
content={"error": str(e)}
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
@app.get("/")
|
| 47 |
-
def read_root():
|
| 48 |
-
return {"message": "Welcome to Flowise Chatbot API"}
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from flowise import Flowise
|
| 4 |
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
print(f"Error initializing Flowise: {e}")
|
| 24 |
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|