Commit
·
2f6a7e7
1
Parent(s):
a6932a7
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,27 @@
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
params = {
|
| 14 |
-
'
|
| 15 |
-
'
|
| 16 |
-
'
|
|
|
|
| 17 |
}
|
| 18 |
-
|
| 19 |
-
response
|
| 20 |
-
|
| 21 |
-
results = response.json()
|
| 22 |
-
|
| 23 |
-
# print(results)
|
| 24 |
-
|
| 25 |
-
if 'items' in results:
|
| 26 |
-
for i in range(min(5, len(results['items']))):
|
| 27 |
-
print(f"Link {i + 1}: {results['items'][i]['link']}")
|
| 28 |
-
return results['items'][:5]
|
| 29 |
else:
|
| 30 |
-
print(
|
| 31 |
-
return
|
| 32 |
|
| 33 |
def tokenize(text):
|
| 34 |
return text
|
|
@@ -69,13 +62,13 @@ def generate(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512
|
|
| 69 |
|
| 70 |
def generateS(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
| 71 |
|
| 72 |
-
stream =
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
return
|
| 79 |
|
| 80 |
additional_inputs=[
|
| 81 |
gr.Textbox(
|
|
@@ -124,7 +117,7 @@ additional_inputs=[
|
|
| 124 |
mychatbot = gr.Chatbot(
|
| 125 |
avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=False)
|
| 126 |
|
| 127 |
-
demo = gr.ChatInterface(fn=
|
| 128 |
chatbot=mychatbot,
|
| 129 |
additional_inputs=additional_inputs,
|
| 130 |
title="Kamran's Mixtral 8x7b Chat",
|
|
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 7 |
|
| 8 |
+
def google_search(query, **kwargs):
|
| 9 |
+
api_key = 'AIzaSyDseKKQCAUBmPidu_QapnpJCGLueDWYJbE'
|
| 10 |
+
cse_id = '001ae9bf840514e61'
|
| 11 |
|
| 12 |
+
service_url = 'https://www.googleapis.com/customsearch/v1'
|
|
|
|
| 13 |
params = {
|
| 14 |
+
'key': api_key,
|
| 15 |
+
'cx': cse_id,
|
| 16 |
+
'q': query,
|
| 17 |
+
**kwargs
|
| 18 |
}
|
| 19 |
+
response = requests.get(service_url, params=params)
|
| 20 |
+
if response.status_code == 200:
|
| 21 |
+
return json.loads(response.text)['items']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
else:
|
| 23 |
+
print(f'Error: {response.status_code}')
|
| 24 |
+
return []
|
| 25 |
|
| 26 |
def tokenize(text):
|
| 27 |
return text
|
|
|
|
| 62 |
|
| 63 |
def generateS(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
| 64 |
|
| 65 |
+
stream = google_search(prompt)
|
| 66 |
+
output = ""
|
| 67 |
|
| 68 |
+
for response in stream:
|
| 69 |
+
output += response.token.text
|
| 70 |
+
yield output
|
| 71 |
+
return output
|
| 72 |
|
| 73 |
additional_inputs=[
|
| 74 |
gr.Textbox(
|
|
|
|
| 117 |
mychatbot = gr.Chatbot(
|
| 118 |
avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=False)
|
| 119 |
|
| 120 |
+
demo = gr.ChatInterface(fn=generateS,
|
| 121 |
chatbot=mychatbot,
|
| 122 |
additional_inputs=additional_inputs,
|
| 123 |
title="Kamran's Mixtral 8x7b Chat",
|