Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,17 @@ import gradio
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
-
from hugchat import hugchat
|
| 6 |
from bardapi import Bard
|
| 7 |
|
| 8 |
auth = os.environ.get('Authorization')
|
|
|
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-xl"
|
| 10 |
headers = {"Authorization": auth}
|
| 11 |
|
| 12 |
-
#Replace XXXX with the values you get from __Secure-1PSID
|
| 13 |
-
os.environ['_BARD_API_KEY']="YQjBGmAPwuH18OslktGRMs3XDGJ8DFlZf4ruCDZe3WOG7Ewk8tiZTnsduSHSs7ErGiIsDA."
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
-
def huggChat(data):
|
| 19 |
-
# start a new huggingchat connection
|
| 20 |
-
chatbot = hugchat.ChatBot(cookie_path="cookies.json")
|
| 21 |
-
|
| 22 |
-
# start a new conversation
|
| 23 |
-
id = chatbot.new_conversation()
|
| 24 |
-
chatbot.change_conversation(id)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
# print the response
|
| 28 |
-
|
| 29 |
-
result = chatbot.chat(data)
|
| 30 |
-
print(result)
|
| 31 |
-
return 'Hello Sir'
|
| 32 |
-
|
| 33 |
def bardChat(data):
|
| 34 |
# Create a session object using the requests library
|
| 35 |
session = requests.Session()
|
|
@@ -45,12 +28,16 @@ def bardChat(data):
|
|
| 45 |
}
|
| 46 |
|
| 47 |
# Set the "__Secure-1PSID" cookie with the Bard API key
|
| 48 |
-
session.cookies.set("__Secure-1PSID",
|
| 49 |
|
| 50 |
# Create a Bard object with the session and a timeout of 30 seconds
|
| 51 |
bard = Bard(session=session, timeout=30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
print(bard.get_answer(data)['content'])
|
| 54 |
|
| 55 |
def query(payload):
|
| 56 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
@@ -62,7 +49,7 @@ def query(payload):
|
|
| 62 |
|
| 63 |
def responsenew(data):
|
| 64 |
return bardChat(data)
|
| 65 |
-
|
| 66 |
#return query({"inputs": "The answer to the universe is",})
|
| 67 |
|
| 68 |
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
import json
|
|
|
|
| 5 |
from bardapi import Bard
|
| 6 |
|
| 7 |
auth = os.environ.get('Authorization')
|
| 8 |
+
bardKey = os.environ.get('_BARD_API_KEY')
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-xl"
|
| 10 |
headers = {"Authorization": auth}
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def bardChat(data):
|
| 17 |
# Create a session object using the requests library
|
| 18 |
session = requests.Session()
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
# Set the "__Secure-1PSID" cookie with the Bard API key
|
| 31 |
+
session.cookies.set("__Secure-1PSID", bardKey)
|
| 32 |
|
| 33 |
# Create a Bard object with the session and a timeout of 30 seconds
|
| 34 |
bard = Bard(session=session, timeout=30)
|
| 35 |
+
answer = bard.get_answer(data)['content']
|
| 36 |
+
print(answer)
|
| 37 |
+
|
| 38 |
+
return json.dumps({'message':answer,'action':'null'})
|
| 39 |
+
|
| 40 |
|
|
|
|
| 41 |
|
| 42 |
def query(payload):
|
| 43 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
| 49 |
|
| 50 |
def responsenew(data):
|
| 51 |
return bardChat(data)
|
| 52 |
+
|
| 53 |
#return query({"inputs": "The answer to the universe is",})
|
| 54 |
|
| 55 |
|