Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import random
|
|
| 4 |
import json
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from pydantic import BaseModel
|
|
|
|
| 7 |
|
| 8 |
# Load the model from Hugging Face
|
| 9 |
nlp = spacy.load("en_pipeline")
|
|
@@ -68,7 +69,11 @@ def get_response(text):
|
|
| 68 |
else:
|
| 69 |
return "I'm not quite sure what you're asking. Could you please provide more details or rephrase your question?"
|
| 70 |
|
| 71 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
class ChatInput(BaseModel):
|
| 74 |
message: str
|
|
@@ -149,20 +154,35 @@ async def get_faqs():
|
|
| 149 |
end_index = start_index + 5
|
| 150 |
return {"faqs": faqs[start_index:end_index]}
|
| 151 |
|
| 152 |
-
@app.get("/", summary="
|
| 153 |
-
def
|
| 154 |
"""
|
| 155 |
-
|
| 156 |
|
| 157 |
Example response:
|
| 158 |
```json
|
| 159 |
{
|
| 160 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
| 162 |
```
|
| 163 |
"""
|
| 164 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
import uvicorn
|
| 168 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 4 |
import json
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
+
from fastapi.responses import HTMLResponse
|
| 8 |
|
| 9 |
# Load the model from Hugging Face
|
| 10 |
nlp = spacy.load("en_pipeline")
|
|
|
|
| 69 |
else:
|
| 70 |
return "I'm not quite sure what you're asking. Could you please provide more details or rephrase your question?"
|
| 71 |
|
| 72 |
+
app = FastAPI(
|
| 73 |
+
title="Intent Classification Chatbot API",
|
| 74 |
+
description="This API provides endpoints for chatting with an intent classification bot, getting intents for messages, and accessing FAQs.",
|
| 75 |
+
version="1.0.0",
|
| 76 |
+
)
|
| 77 |
|
| 78 |
class ChatInput(BaseModel):
|
| 79 |
message: str
|
|
|
|
| 154 |
end_index = start_index + 5
|
| 155 |
return {"faqs": faqs[start_index:end_index]}
|
| 156 |
|
| 157 |
+
@app.get("/intents", summary="Get all available intent categories", response_description="List of all intent categories")
|
| 158 |
+
async def get_intents():
|
| 159 |
"""
|
| 160 |
+
This endpoint returns a list of all available intent categories supported by the chatbot.
|
| 161 |
|
| 162 |
Example response:
|
| 163 |
```json
|
| 164 |
{
|
| 165 |
+
"intents": [
|
| 166 |
+
"get_invoice",
|
| 167 |
+
"payment_issue",
|
| 168 |
+
"check_invoice",
|
| 169 |
+
"contact_customer_service",
|
| 170 |
+
...
|
| 171 |
+
]
|
| 172 |
}
|
| 173 |
```
|
| 174 |
"""
|
| 175 |
+
return {"intents": list(intents_responses.keys())}
|
| 176 |
+
|
| 177 |
+
@app.get("/", response_class=HTMLResponse)
|
| 178 |
+
async def read_root():
|
| 179 |
+
"""
|
| 180 |
+
Root endpoint that returns an HTML page with information about the API.
|
| 181 |
+
"""
|
| 182 |
+
with open("index.html", "r") as f:
|
| 183 |
+
html_content = f.read()
|
| 184 |
+
return HTMLResponse(content=html_content, status_code=200)
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|
| 187 |
import uvicorn
|
| 188 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|