Download app.py from geovannaw/testeapi: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/geovannaw/testeapi/resolve/main/app.py
- Command line
-
hf download hf://spaces/geovannaw/testeapi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/geovannaw/testeapi/resolve/main/app.py
1.15 kB
| from fastapi import FastAPI, Request | |
| from fastapi.responses import PlainTextResponse | |
| import requests | |
| app = FastAPI() | |
| # Dicionário para armazenar o histórico de conversas | |
| conversation_histories = {} | |
| API_URL = "https://fabiosantos-ia.hf.space/api/v1/prediction/a953ea1b-ee34-4ae3-9b25-b82c814dd871" | |
| def query(payload): | |
| response = requests.post(API_URL, json=payload) #envia a pergunta pelo url da api para a IA | |
| return response.json() #guarda a resposta | |
| #endpoint do twilio | |
| async def reply_whatsapp(request: Request): #recebe a mensagem do usuario | |
| form = await request.form() | |
| incoming_msg = form.get('Body', '').lower() #guarda a mensagem do usuario | |
| from_number = form.get('From') | |
| print(incoming_msg) | |
| print(from_number) | |
| # Get the user's conversation history, if it exists | |
| user_history = conversation_histories.get(from_number, []) | |
| output = query({ | |
| "question": incoming_msg, #leva o que usuario falou para IA pela função query | |
| }) | |
| return PlainTextResponse(output['text'], status_code=200) | |