Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,11 @@ from flask import Flask, request
|
|
| 2 |
from twilio.twiml.messaging_response import MessagingResponse
|
| 3 |
from twilio.rest import Client
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
from bs4 import BeautifulSoup
|
| 8 |
import requests
|
| 9 |
from requests.auth import HTTPBasicAuth
|
| 10 |
-
|
| 11 |
-
from io import BytesIO
|
| 12 |
-
import pandas as pd
|
| 13 |
-
from urllib.parse import urlparse
|
| 14 |
-
from pypdf import PdfReader
|
| 15 |
-
from ai71 import AI71
|
| 16 |
-
import uuid
|
| 17 |
-
from inference_sdk import InferenceHTTPClient
|
| 18 |
-
import base64
|
| 19 |
|
| 20 |
app = Flask(__name__)
|
| 21 |
UPLOAD_FOLDER = '/code/uploads'
|
|
@@ -37,9 +28,23 @@ Answer the question based only on the following context:
|
|
| 37 |
---
|
| 38 |
Answer the question based on the above context: {question}
|
| 39 |
"""
|
|
|
|
|
|
|
| 40 |
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
@app.route('/whatsapp', methods=['POST'])
|
| 44 |
def whatsapp_webhook():
|
| 45 |
global bookdata
|
|
|
|
| 2 |
from twilio.twiml.messaging_response import MessagingResponse
|
| 3 |
from twilio.rest import Client
|
| 4 |
import os
|
| 5 |
+
from mistralai import Mistral
|
| 6 |
+
|
|
|
|
| 7 |
import requests
|
| 8 |
from requests.auth import HTTPBasicAuth
|
| 9 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
UPLOAD_FOLDER = '/code/uploads'
|
|
|
|
| 28 |
---
|
| 29 |
Answer the question based on the above context: {question}
|
| 30 |
"""
|
| 31 |
+
model = "mistral-large-latest"
|
| 32 |
+
api_key='xQ2Zhfsp4cLar4lvBRDWZKljvp0Ej427'
|
| 33 |
|
| 34 |
+
client = Mistral(api_key=api_key)
|
| 35 |
|
| 36 |
+
def generate_response(query,chat_history):
|
| 37 |
+
|
| 38 |
+
chat_response = client.chat.complete(
|
| 39 |
+
model= model,
|
| 40 |
+
messages = [
|
| 41 |
+
{
|
| 42 |
+
"role": "user",
|
| 43 |
+
"content": f"{query}? provide response within 2 sentence",
|
| 44 |
+
},
|
| 45 |
+
]
|
| 46 |
+
)
|
| 47 |
+
return chat_response.choices[0].message.content
|
| 48 |
@app.route('/whatsapp', methods=['POST'])
|
| 49 |
def whatsapp_webhook():
|
| 50 |
global bookdata
|