RiohDigital
commited on
Commit
•
83ef6a0
1
Parent(s):
2395da0
Upload 3 files
Browse files- Dockerfile +16 -0
- app.py +32 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
RUN useradd -m -u 1000 user
|
7 |
+
|
8 |
+
WORKDIR /app
|
9 |
+
|
10 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
11 |
+
|
12 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
13 |
+
|
14 |
+
COPY --chown=user . /app
|
15 |
+
|
16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from fastapi.responses import PlainTextResponse
|
3 |
+
import requests
|
4 |
+
|
5 |
+
app = FastAPI ()
|
6 |
+
|
7 |
+
# Dicionário para armazenar o histórico de conversas
|
8 |
+
conversatio_histories = {}
|
9 |
+
|
10 |
+
API_URL = "https://riohdigital-riohchatbotpizzaria.hf.space/chatbot/f315e661-cb9b-407a-b1de-6ad0aea9f3ae"
|
11 |
+
|
12 |
+
def query(payload):
|
13 |
+
response = requests.post(API_URL, json=payload)
|
14 |
+
return response.json()
|
15 |
+
|
16 |
+
@app.post("/whatsapp")
|
17 |
+
async def reply_whatsapp(request: Request):
|
18 |
+
form = await request.form()
|
19 |
+
incoming_msg = form.get('Body', '').lower()
|
20 |
+
from_number = form.get('from')
|
21 |
+
|
22 |
+
print(incoming_msg)
|
23 |
+
print(from_number)
|
24 |
+
|
25 |
+
# Get the user's conversation hisory, if it exists
|
26 |
+
user_history = conversatio_histories.get(from_number, [])
|
27 |
+
|
28 |
+
output = query({
|
29 |
+
"question": incoming_msg,
|
30 |
+
})
|
31 |
+
|
32 |
+
return PlainTextResponse(output['text'], status_code=200)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|
3 |
+
twilio
|