geovannaw commited on
Commit
080b840
verified
1 Parent(s): 402bef7

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +33 -0
  3. 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,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ conversation_histories = {}
9
+
10
+ API_URL = "https://fabiosantos-ia.hf.space/api/v1/prediction/a953ea1b-ee34-4ae3-9b25-b82c814dd871"
11
+
12
+ def query(payload):
13
+ response = requests.post(API_URL, json=payload) #envia a pergunta pelo url da api para a IA
14
+ return response.json() #guarda a resposta
15
+
16
+ @app.post("/whatsapp") #endpoint do twilio
17
+ async def reply_whatsapp(request: Request): #recebe a mensagem do usuario
18
+ form = await request.form()
19
+ incoming_msg = form.get('Body', '').lower() #guarda a mensagem do usuario
20
+ from_number = form.get('From')
21
+
22
+ print(incoming_msg)
23
+ print(from_number)
24
+
25
+ # Get the user's conversation history, if it exists
26
+ user_history = conversation_histories.get(from_number, [])
27
+
28
+ output = query({
29
+ "question": incoming_msg, #leva o que usuario falou para IA pela fun莽茫o query
30
+ })
31
+
32
+
33
+ return PlainTextResponse(output['text'], status_code=200)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ twilio