Duplicate from CobaltZvc/HyperBot
Browse filesCo-authored-by: Vishwesh V Bhat <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +1025 -0
- logs.csv +1 -0
- requirements.txt +24 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: HyperBot
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: gray
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.17.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: CobaltZvc/HyperBot
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,1025 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import wget
|
4 |
+
import streamlit as st
|
5 |
+
from PIL import Image
|
6 |
+
from serpapi import GoogleSearch
|
7 |
+
import torch
|
8 |
+
from diffusers import StableDiffusionPipeline
|
9 |
+
from bokeh.models.widgets import Button
|
10 |
+
from bokeh.models.widgets.buttons import Button
|
11 |
+
from bokeh.models import CustomJS
|
12 |
+
from streamlit_bokeh_events import streamlit_bokeh_events
|
13 |
+
import base64
|
14 |
+
from streamlit_player import st_player
|
15 |
+
from pytube import YouTube
|
16 |
+
from pytube import Search
|
17 |
+
import io
|
18 |
+
import warnings
|
19 |
+
from PIL import Image
|
20 |
+
from stability_sdk import client
|
21 |
+
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
|
22 |
+
import datetime
|
23 |
+
from google.oauth2 import service_account
|
24 |
+
from googleapiclient.discovery import build
|
25 |
+
import wget
|
26 |
+
import urllib.request
|
27 |
+
import csv
|
28 |
+
|
29 |
+
|
30 |
+
def save_uploadedfile(uploadedfile):
|
31 |
+
with open(uploadedfile.name,"wb") as f:
|
32 |
+
f.write(uploadedfile.getbuffer())
|
33 |
+
|
34 |
+
stability_api = client.StabilityInference(
|
35 |
+
key=st.secrets["STABILITY_KEY"], #os.environ("STABILITY_KEY"), # key=os.environ['STABILITY_KEY'], # API Key reference.
|
36 |
+
verbose=True, # Print debug messages.
|
37 |
+
engine="stable-diffusion-v1-5", # Set the engine to use for generation.
|
38 |
+
# Available engines: stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0
|
39 |
+
# stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-inpainting-v1-0 stable-inpainting-512-v2-0
|
40 |
+
)
|
41 |
+
|
42 |
+
header = ["sl. no.", "Input Prompt", "Output", "Date_time"]
|
43 |
+
|
44 |
+
def csv_logs(mytext, result, date_time):
|
45 |
+
with open("logs.csv", "r") as file:
|
46 |
+
sl_no = sum(1 for _ in csv.reader(file))
|
47 |
+
|
48 |
+
with open("logs.csv", "a", newline="") as file:
|
49 |
+
writer = csv.writer(file)
|
50 |
+
writer.writerow([sl_no, mytext, result, date_time])
|
51 |
+
|
52 |
+
def search_internet(question):
|
53 |
+
try:
|
54 |
+
params = {
|
55 |
+
"q": question,
|
56 |
+
"location": "Bengaluru, Karnataka, India",
|
57 |
+
"hl": "hi",
|
58 |
+
"gl": "in",
|
59 |
+
"google_domain": "google.co.in",
|
60 |
+
# "api_key": ""
|
61 |
+
"api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
62 |
+
}
|
63 |
+
|
64 |
+
params = {
|
65 |
+
"q": question,
|
66 |
+
"location": "Bengaluru, Karnataka, India",
|
67 |
+
"hl": "hi",
|
68 |
+
"gl": "in",
|
69 |
+
"google_domain": "google.co.in",
|
70 |
+
# "api_key": ""
|
71 |
+
"api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
72 |
+
}
|
73 |
+
|
74 |
+
search = GoogleSearch(params)
|
75 |
+
results = search.get_dict()
|
76 |
+
organic_results = results["organic_results"]
|
77 |
+
st.text("Key 0 used")
|
78 |
+
|
79 |
+
|
80 |
+
snippets = ""
|
81 |
+
counter = 1
|
82 |
+
for item in organic_results:
|
83 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
84 |
+
counter += 1
|
85 |
+
|
86 |
+
# snippets
|
87 |
+
|
88 |
+
response = openai.Completion.create(
|
89 |
+
model="text-davinci-003",
|
90 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
91 |
+
temperature=0.49,
|
92 |
+
max_tokens=256,
|
93 |
+
top_p=1,
|
94 |
+
frequency_penalty=0,
|
95 |
+
presence_penalty=0)
|
96 |
+
|
97 |
+
now = datetime.datetime.now()
|
98 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
99 |
+
string_temp = response.choices[0].text
|
100 |
+
csv_logs(question, string_temp, date_time)
|
101 |
+
st.write(string_temp)
|
102 |
+
st.write(snippets)
|
103 |
+
except:
|
104 |
+
try:
|
105 |
+
|
106 |
+
params = {
|
107 |
+
"q": question,
|
108 |
+
"location": "Bengaluru, Karnataka, India",
|
109 |
+
"hl": "hi",
|
110 |
+
"gl": "in",
|
111 |
+
"google_domain": "google.co.in",
|
112 |
+
# "api_key": ""
|
113 |
+
"api_key": st.secrets["GOOGLE_API1"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
114 |
+
}
|
115 |
+
|
116 |
+
params = {
|
117 |
+
"q": question,
|
118 |
+
"location": "Bengaluru, Karnataka, India",
|
119 |
+
"hl": "hi",
|
120 |
+
"gl": "in",
|
121 |
+
"google_domain": "google.co.in",
|
122 |
+
# "api_key": ""
|
123 |
+
"api_key": st.secrets["GOOGLE_API1"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
124 |
+
}
|
125 |
+
|
126 |
+
search = GoogleSearch(params)
|
127 |
+
results = search.get_dict()
|
128 |
+
organic_results = results["organic_results"]
|
129 |
+
st.text("Key 1 used")
|
130 |
+
|
131 |
+
|
132 |
+
snippets = ""
|
133 |
+
counter = 1
|
134 |
+
for item in organic_results:
|
135 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
136 |
+
counter += 1
|
137 |
+
|
138 |
+
# snippets
|
139 |
+
|
140 |
+
response = openai.Completion.create(
|
141 |
+
model="text-davinci-003",
|
142 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
143 |
+
temperature=0.49,
|
144 |
+
max_tokens=256,
|
145 |
+
top_p=1,
|
146 |
+
frequency_penalty=0,
|
147 |
+
presence_penalty=0)
|
148 |
+
|
149 |
+
now = datetime.datetime.now()
|
150 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
151 |
+
string_temp = response.choices[0].text
|
152 |
+
csv_logs(question, string_temp, date_time)
|
153 |
+
st.write(string_temp)
|
154 |
+
st.write(snippets)
|
155 |
+
except:
|
156 |
+
try:
|
157 |
+
|
158 |
+
params = {
|
159 |
+
"q": question,
|
160 |
+
"location": "Bengaluru, Karnataka, India",
|
161 |
+
"hl": "hi",
|
162 |
+
"gl": "in",
|
163 |
+
"google_domain": "google.co.in",
|
164 |
+
# "api_key": ""
|
165 |
+
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
166 |
+
}
|
167 |
+
|
168 |
+
params = {
|
169 |
+
"q": question,
|
170 |
+
"location": "Bengaluru, Karnataka, India",
|
171 |
+
"hl": "hi",
|
172 |
+
"gl": "in",
|
173 |
+
"google_domain": "google.co.in",
|
174 |
+
# "api_key": ""
|
175 |
+
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
176 |
+
}
|
177 |
+
|
178 |
+
search = GoogleSearch(params)
|
179 |
+
results = search.get_dict()
|
180 |
+
organic_results = results["organic_results"]
|
181 |
+
st.text("Key 2 used")
|
182 |
+
|
183 |
+
|
184 |
+
snippets = ""
|
185 |
+
counter = 1
|
186 |
+
for item in organic_results:
|
187 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
188 |
+
counter += 1
|
189 |
+
|
190 |
+
# snippets
|
191 |
+
|
192 |
+
response = openai.Completion.create(
|
193 |
+
model="text-davinci-003",
|
194 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
195 |
+
temperature=0.49,
|
196 |
+
max_tokens=256,
|
197 |
+
top_p=1,
|
198 |
+
frequency_penalty=0,
|
199 |
+
presence_penalty=0)
|
200 |
+
|
201 |
+
now = datetime.datetime.now()
|
202 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
203 |
+
string_temp = response.choices[0].text
|
204 |
+
csv_logs(question, string_temp, date_time)
|
205 |
+
st.write(string_temp)
|
206 |
+
st.write(snippets)
|
207 |
+
except:
|
208 |
+
try:
|
209 |
+
|
210 |
+
params = {
|
211 |
+
"q": question,
|
212 |
+
"location": "Bengaluru, Karnataka, India",
|
213 |
+
"hl": "hi",
|
214 |
+
"gl": "in",
|
215 |
+
"google_domain": "google.co.in",
|
216 |
+
# "api_key": ""
|
217 |
+
"api_key": st.secrets["GOOGLE_API3"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
218 |
+
}
|
219 |
+
|
220 |
+
params = {
|
221 |
+
"q": question,
|
222 |
+
"location": "Bengaluru, Karnataka, India",
|
223 |
+
"hl": "hi",
|
224 |
+
"gl": "in",
|
225 |
+
"google_domain": "google.co.in",
|
226 |
+
# "api_key": ""
|
227 |
+
"api_key": st.secrets["GOOGLE_API3"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
228 |
+
}
|
229 |
+
|
230 |
+
search = GoogleSearch(params)
|
231 |
+
results = search.get_dict()
|
232 |
+
organic_results = results["organic_results"]
|
233 |
+
st.text("Key 3 used")
|
234 |
+
|
235 |
+
|
236 |
+
snippets = ""
|
237 |
+
counter = 1
|
238 |
+
for item in organic_results:
|
239 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
240 |
+
counter += 1
|
241 |
+
|
242 |
+
# snippets
|
243 |
+
|
244 |
+
response = openai.Completion.create(
|
245 |
+
model="text-davinci-003",
|
246 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
247 |
+
temperature=0.49,
|
248 |
+
max_tokens=256,
|
249 |
+
top_p=1,
|
250 |
+
frequency_penalty=0,
|
251 |
+
presence_penalty=0)
|
252 |
+
|
253 |
+
now = datetime.datetime.now()
|
254 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
255 |
+
string_temp = response.choices[0].text
|
256 |
+
csv_logs(question, string_temp, date_time)
|
257 |
+
st.write(string_temp)
|
258 |
+
st.write(snippets)
|
259 |
+
except:
|
260 |
+
try:
|
261 |
+
|
262 |
+
params = {
|
263 |
+
"q": question,
|
264 |
+
"location": "Bengaluru, Karnataka, India",
|
265 |
+
"hl": "hi",
|
266 |
+
"gl": "in",
|
267 |
+
"google_domain": "google.co.in",
|
268 |
+
# "api_key": ""
|
269 |
+
"api_key": st.secrets["GOOGLE_API4"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
270 |
+
}
|
271 |
+
|
272 |
+
params = {
|
273 |
+
"q": question,
|
274 |
+
"location": "Bengaluru, Karnataka, India",
|
275 |
+
"hl": "hi",
|
276 |
+
"gl": "in",
|
277 |
+
"google_domain": "google.co.in",
|
278 |
+
# "api_key": ""
|
279 |
+
"api_key": st.secrets["GOOGLE_API4"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
280 |
+
}
|
281 |
+
|
282 |
+
search = GoogleSearch(params)
|
283 |
+
results = search.get_dict()
|
284 |
+
organic_results = results["organic_results"]
|
285 |
+
st.text("Key 4 used")
|
286 |
+
|
287 |
+
|
288 |
+
snippets = ""
|
289 |
+
counter = 1
|
290 |
+
for item in organic_results:
|
291 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
292 |
+
counter += 1
|
293 |
+
|
294 |
+
# snippets
|
295 |
+
|
296 |
+
response = openai.Completion.create(
|
297 |
+
model="text-davinci-003",
|
298 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
299 |
+
temperature=0.49,
|
300 |
+
max_tokens=256,
|
301 |
+
top_p=1,
|
302 |
+
frequency_penalty=0,
|
303 |
+
presence_penalty=0)
|
304 |
+
|
305 |
+
now = datetime.datetime.now()
|
306 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
307 |
+
string_temp = response.choices[0].text
|
308 |
+
csv_logs(question, string_temp, date_time)
|
309 |
+
st.write(string_temp)
|
310 |
+
st.write(snippets)
|
311 |
+
except:
|
312 |
+
try:
|
313 |
+
|
314 |
+
params = {
|
315 |
+
"q": question,
|
316 |
+
"location": "Bengaluru, Karnataka, India",
|
317 |
+
"hl": "hi",
|
318 |
+
"gl": "in",
|
319 |
+
"google_domain": "google.co.in",
|
320 |
+
# "api_key": ""
|
321 |
+
"api_key": st.secrets["GOOGLE_API5"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
322 |
+
}
|
323 |
+
|
324 |
+
params = {
|
325 |
+
"q": question,
|
326 |
+
"location": "Bengaluru, Karnataka, India",
|
327 |
+
"hl": "hi",
|
328 |
+
"gl": "in",
|
329 |
+
"google_domain": "google.co.in",
|
330 |
+
# "api_key": ""
|
331 |
+
"api_key": st.secrets["GOOGLE_API5"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
332 |
+
}
|
333 |
+
|
334 |
+
search = GoogleSearch(params)
|
335 |
+
results = search.get_dict()
|
336 |
+
organic_results = results["organic_results"]
|
337 |
+
st.text("Key 5 used")
|
338 |
+
|
339 |
+
|
340 |
+
snippets = ""
|
341 |
+
counter = 1
|
342 |
+
for item in organic_results:
|
343 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
344 |
+
counter += 1
|
345 |
+
|
346 |
+
# snippets
|
347 |
+
|
348 |
+
response = openai.Completion.create(
|
349 |
+
model="text-davinci-003",
|
350 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
351 |
+
temperature=0.49,
|
352 |
+
max_tokens=256,
|
353 |
+
top_p=1,
|
354 |
+
frequency_penalty=0,
|
355 |
+
presence_penalty=0)
|
356 |
+
|
357 |
+
now = datetime.datetime.now()
|
358 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
359 |
+
string_temp = response.choices[0].text
|
360 |
+
csv_logs(question, string_temp, date_time)
|
361 |
+
st.write(string_temp)
|
362 |
+
st.write(snippets)
|
363 |
+
except:
|
364 |
+
try:
|
365 |
+
|
366 |
+
params = {
|
367 |
+
"q": question,
|
368 |
+
"location": "Bengaluru, Karnataka, India",
|
369 |
+
"hl": "hi",
|
370 |
+
"gl": "in",
|
371 |
+
"google_domain": "google.co.in",
|
372 |
+
# "api_key": ""
|
373 |
+
"api_key": st.secrets["GOOGLE_API6"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
374 |
+
}
|
375 |
+
|
376 |
+
params = {
|
377 |
+
"q": question,
|
378 |
+
"location": "Bengaluru, Karnataka, India",
|
379 |
+
"hl": "hi",
|
380 |
+
"gl": "in",
|
381 |
+
"google_domain": "google.co.in",
|
382 |
+
# "api_key": ""
|
383 |
+
"api_key": st.secrets["GOOGLE_API6"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
384 |
+
}
|
385 |
+
|
386 |
+
search = GoogleSearch(params)
|
387 |
+
results = search.get_dict()
|
388 |
+
organic_results = results["organic_results"]
|
389 |
+
st.text("Key 6 used")
|
390 |
+
|
391 |
+
|
392 |
+
snippets = ""
|
393 |
+
counter = 1
|
394 |
+
for item in organic_results:
|
395 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
396 |
+
counter += 1
|
397 |
+
|
398 |
+
# snippets
|
399 |
+
|
400 |
+
response = openai.Completion.create(
|
401 |
+
model="text-davinci-003",
|
402 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
403 |
+
temperature=0.49,
|
404 |
+
max_tokens=256,
|
405 |
+
top_p=1,
|
406 |
+
frequency_penalty=0,
|
407 |
+
presence_penalty=0)
|
408 |
+
|
409 |
+
now = datetime.datetime.now()
|
410 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
411 |
+
string_temp = response.choices[0].text
|
412 |
+
csv_logs(question, string_temp, date_time)
|
413 |
+
st.write(string_temp)
|
414 |
+
st.write(snippets)
|
415 |
+
except:
|
416 |
+
try:
|
417 |
+
|
418 |
+
params = {
|
419 |
+
"q": question,
|
420 |
+
"location": "Bengaluru, Karnataka, India",
|
421 |
+
"hl": "hi",
|
422 |
+
"gl": "in",
|
423 |
+
"google_domain": "google.co.in",
|
424 |
+
# "api_key": ""
|
425 |
+
"api_key": st.secrets["GOOGLE_API7"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
426 |
+
}
|
427 |
+
|
428 |
+
params = {
|
429 |
+
"q": question,
|
430 |
+
"location": "Bengaluru, Karnataka, India",
|
431 |
+
"hl": "hi",
|
432 |
+
"gl": "in",
|
433 |
+
"google_domain": "google.co.in",
|
434 |
+
# "api_key": ""
|
435 |
+
"api_key": st.secrets["GOOGLE_API7"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
436 |
+
}
|
437 |
+
|
438 |
+
search = GoogleSearch(params)
|
439 |
+
results = search.get_dict()
|
440 |
+
organic_results = results["organic_results"]
|
441 |
+
st.text("Key 7 used")
|
442 |
+
|
443 |
+
|
444 |
+
snippets = ""
|
445 |
+
counter = 1
|
446 |
+
for item in organic_results:
|
447 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
448 |
+
counter += 1
|
449 |
+
|
450 |
+
# snippets
|
451 |
+
|
452 |
+
response = openai.Completion.create(
|
453 |
+
model="text-davinci-003",
|
454 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
455 |
+
temperature=0.49,
|
456 |
+
max_tokens=256,
|
457 |
+
top_p=1,
|
458 |
+
frequency_penalty=0,
|
459 |
+
presence_penalty=0)
|
460 |
+
|
461 |
+
now = datetime.datetime.now()
|
462 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
463 |
+
string_temp = response.choices[0].text
|
464 |
+
csv_logs(question, string_temp, date_time)
|
465 |
+
st.write(string_temp)
|
466 |
+
st.write(snippets)
|
467 |
+
except:
|
468 |
+
try:
|
469 |
+
|
470 |
+
params = {
|
471 |
+
"q": question,
|
472 |
+
"location": "Bengaluru, Karnataka, India",
|
473 |
+
"hl": "hi",
|
474 |
+
"gl": "in",
|
475 |
+
"google_domain": "google.co.in",
|
476 |
+
# "api_key": ""
|
477 |
+
"api_key": st.secrets["GOOGLE_API8"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
478 |
+
}
|
479 |
+
|
480 |
+
params = {
|
481 |
+
"q": question,
|
482 |
+
"location": "Bengaluru, Karnataka, India",
|
483 |
+
"hl": "hi",
|
484 |
+
"gl": "in",
|
485 |
+
"google_domain": "google.co.in",
|
486 |
+
# "api_key": ""
|
487 |
+
"api_key": st.secrets["GOOGLE_API8"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
488 |
+
}
|
489 |
+
|
490 |
+
search = GoogleSearch(params)
|
491 |
+
results = search.get_dict()
|
492 |
+
organic_results = results["organic_results"]
|
493 |
+
st.text("Key 8 used")
|
494 |
+
|
495 |
+
|
496 |
+
snippets = ""
|
497 |
+
counter = 1
|
498 |
+
for item in organic_results:
|
499 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
500 |
+
counter += 1
|
501 |
+
|
502 |
+
# snippets
|
503 |
+
|
504 |
+
response = openai.Completion.create(
|
505 |
+
model="text-davinci-003",
|
506 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
507 |
+
temperature=0.49,
|
508 |
+
max_tokens=256,
|
509 |
+
top_p=1,
|
510 |
+
frequency_penalty=0,
|
511 |
+
presence_penalty=0)
|
512 |
+
|
513 |
+
now = datetime.datetime.now()
|
514 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
515 |
+
string_temp = response.choices[0].text
|
516 |
+
csv_logs(question, string_temp, date_time)
|
517 |
+
st.write(string_temp)
|
518 |
+
st.write(snippets)
|
519 |
+
except:
|
520 |
+
try:
|
521 |
+
|
522 |
+
params = {
|
523 |
+
"q": question,
|
524 |
+
"location": "Bengaluru, Karnataka, India",
|
525 |
+
"hl": "hi",
|
526 |
+
"gl": "in",
|
527 |
+
"google_domain": "google.co.in",
|
528 |
+
# "api_key": ""
|
529 |
+
"api_key": st.secrets["GOOGLE_API9"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
530 |
+
}
|
531 |
+
|
532 |
+
params = {
|
533 |
+
"q": question,
|
534 |
+
"location": "Bengaluru, Karnataka, India",
|
535 |
+
"hl": "hi",
|
536 |
+
"gl": "in",
|
537 |
+
"google_domain": "google.co.in",
|
538 |
+
# "api_key": ""
|
539 |
+
"api_key": st.secrets["GOOGLE_API9"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
540 |
+
}
|
541 |
+
|
542 |
+
search = GoogleSearch(params)
|
543 |
+
results = search.get_dict()
|
544 |
+
organic_results = results["organic_results"]
|
545 |
+
st.text("Key 9 used")
|
546 |
+
|
547 |
+
|
548 |
+
snippets = ""
|
549 |
+
counter = 1
|
550 |
+
for item in organic_results:
|
551 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
552 |
+
counter += 1
|
553 |
+
|
554 |
+
# snippets
|
555 |
+
|
556 |
+
response = openai.Completion.create(
|
557 |
+
model="text-davinci-003",
|
558 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
559 |
+
temperature=0.49,
|
560 |
+
max_tokens=256,
|
561 |
+
top_p=1,
|
562 |
+
frequency_penalty=0,
|
563 |
+
presence_penalty=0)
|
564 |
+
|
565 |
+
now = datetime.datetime.now()
|
566 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
567 |
+
string_temp = response.choices[0].text
|
568 |
+
csv_logs(question, string_temp, date_time)
|
569 |
+
st.write(string_temp)
|
570 |
+
st.write(snippets)
|
571 |
+
except:
|
572 |
+
try:
|
573 |
+
|
574 |
+
params = {
|
575 |
+
"q": question,
|
576 |
+
"location": "Bengaluru, Karnataka, India",
|
577 |
+
"hl": "hi",
|
578 |
+
"gl": "in",
|
579 |
+
"google_domain": "google.co.in",
|
580 |
+
# "api_key": ""
|
581 |
+
"api_key": st.secrets["GOOGLE_API10"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
582 |
+
}
|
583 |
+
|
584 |
+
params = {
|
585 |
+
"q": question,
|
586 |
+
"location": "Bengaluru, Karnataka, India",
|
587 |
+
"hl": "hi",
|
588 |
+
"gl": "in",
|
589 |
+
"google_domain": "google.co.in",
|
590 |
+
# "api_key": ""
|
591 |
+
"api_key": st.secrets["GOOGLE_API10"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
592 |
+
}
|
593 |
+
|
594 |
+
search = GoogleSearch(params)
|
595 |
+
results = search.get_dict()
|
596 |
+
organic_results = results["organic_results"]
|
597 |
+
st.text("Key 10 used")
|
598 |
+
|
599 |
+
|
600 |
+
snippets = ""
|
601 |
+
counter = 1
|
602 |
+
for item in organic_results:
|
603 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
604 |
+
counter += 1
|
605 |
+
|
606 |
+
# snippets
|
607 |
+
|
608 |
+
response = openai.Completion.create(
|
609 |
+
model="text-davinci-003",
|
610 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
611 |
+
temperature=0.49,
|
612 |
+
max_tokens=256,
|
613 |
+
top_p=1,
|
614 |
+
frequency_penalty=0,
|
615 |
+
presence_penalty=0)
|
616 |
+
|
617 |
+
now = datetime.datetime.now()
|
618 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
619 |
+
string_temp = response.choices[0].text
|
620 |
+
csv_logs(question, string_temp, date_time)
|
621 |
+
st.write(string_temp)
|
622 |
+
st.write(snippets)
|
623 |
+
except:
|
624 |
+
pass
|
625 |
+
|
626 |
+
|
627 |
+
|
628 |
+
openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ['OPENAI_KEY']
|
629 |
+
# date_time = str(datetime.now())
|
630 |
+
|
631 |
+
openai.api_key = st.secrets["OPENAI_KEY"]
|
632 |
+
|
633 |
+
def openai_response(PROMPT):
|
634 |
+
response = openai.Image.create(
|
635 |
+
prompt=PROMPT,
|
636 |
+
n=1,
|
637 |
+
size="256x256",
|
638 |
+
)
|
639 |
+
return response["data"][0]["url"]
|
640 |
+
|
641 |
+
st.title("Hi! :red[HyperBot] here!!🤖⭐️")
|
642 |
+
st.title("Go on ask me anything!!")
|
643 |
+
|
644 |
+
st.write('''
|
645 |
+
⭐️ *HyperBot is your virtual assistant powered by Whisper /
|
646 |
+
chatgpt / internet / Dall-E / OpenAI embeddings - the perfect
|
647 |
+
companion for you. With HyperBot, you can ask anything you ask
|
648 |
+
internet everyday . Get answers to questions about the weather,
|
649 |
+
stocks 📈, news📰, and more! Plus, you can also generate 🖌️
|
650 |
+
paintings, drawings, abstract art 🎨, play music 🎵 or videos,
|
651 |
+
create tweets 🐦 and posts 📝, and compose emails 📧 - all with
|
652 |
+
the help of HyperBot!* 🤖 ✨
|
653 |
+
''')
|
654 |
+
|
655 |
+
st.text('''You can ask me:
|
656 |
+
1. All the things you ask ChatGPT.
|
657 |
+
2. To generate paintings, drawings, abstract art.
|
658 |
+
3. Music or Videos
|
659 |
+
4. Weather
|
660 |
+
5. Stocks
|
661 |
+
6. Current Affairs and News.
|
662 |
+
7. Create or compose tweets or Linkedin posts or email.''')
|
663 |
+
|
664 |
+
Input_type = st.radio(
|
665 |
+
"**Input type:**",
|
666 |
+
('TEXT', 'SPEECH')
|
667 |
+
)
|
668 |
+
|
669 |
+
if Input_type == 'TEXT':
|
670 |
+
mytext = st.text_input('**Go on! Ask me anything:**')
|
671 |
+
if st.button("SUBMIT"):
|
672 |
+
question=mytext
|
673 |
+
response = openai.Completion.create(
|
674 |
+
model="text-davinci-003",
|
675 |
+
prompt=f'''Your name is HyperBot and knowledge cutoff date is 2021-09, and you are not aware of any events after that time. if the
|
676 |
+
Answer to following questions is not from your knowledge base or in case of queries like date, time, weather
|
677 |
+
updates / stock updates / current affairs / news or people which requires you to have internet connection then print i don't have access to internet to answer your question,
|
678 |
+
if question is related to image or painting or drawing or diagram generation then print ipython type output function gen_draw("detailed prompt of image to be generated")
|
679 |
+
if the question is related to playing a song or video or music of a singer then print ipython type output function vid_tube("relevent search query")
|
680 |
+
if the question is related to operating home appliances then print ipython type output function home_app(" action(ON/Off),appliance(TV,Geaser,Fridge,Lights,fans,AC)") .
|
681 |
+
if question is realted to sending mail or sms then print ipython type output function messenger_app(" message of us ,messenger(email,sms)")
|
682 |
+
\nQuestion-{question}
|
683 |
+
\nAnswer -''',
|
684 |
+
temperature=0.49,
|
685 |
+
max_tokens=256,
|
686 |
+
top_p=1,
|
687 |
+
frequency_penalty=0,
|
688 |
+
presence_penalty=0
|
689 |
+
)
|
690 |
+
string_temp=response.choices[0].text
|
691 |
+
|
692 |
+
if ("gen_draw" in string_temp):
|
693 |
+
try:
|
694 |
+
try:
|
695 |
+
wget.download(openai_response(prompt))
|
696 |
+
img2 = Image.open(wget.download(openai_response(prompt)))
|
697 |
+
img2.show()
|
698 |
+
rx = 'Image returned'
|
699 |
+
now = datetime.datetime.now()
|
700 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
701 |
+
csv_logs(mytext, rx, date_time)
|
702 |
+
except:
|
703 |
+
urllib.request.urlretrieve(openai_response(prompt),"img_ret.png")
|
704 |
+
img = Image.open("img_ret.png")
|
705 |
+
img.show()
|
706 |
+
rx = 'Image returned'
|
707 |
+
now = datetime.datetime.now()
|
708 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
709 |
+
csv_logs(mytext, rx, date_time)
|
710 |
+
except:
|
711 |
+
# Set up our initial generation parameters.
|
712 |
+
answers = stability_api.generate(
|
713 |
+
prompt = mytext,
|
714 |
+
seed=992446758, # If a seed is provided, the resulting generated image will be deterministic.
|
715 |
+
# What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.
|
716 |
+
# Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.
|
717 |
+
steps=30, # Amount of inference steps performed on image generation. Defaults to 30.
|
718 |
+
cfg_scale=8.0, # Influences how strongly your generation is guided to match your prompt.
|
719 |
+
# Setting this value higher increases the strength in which it tries to match your prompt.
|
720 |
+
# Defaults to 7.0 if not specified.
|
721 |
+
width=512, # Generation width, defaults to 512 if not included.
|
722 |
+
height=512, # Generation height, defaults to 512 if not included.
|
723 |
+
samples=1, # Number of images to generate, defaults to 1 if not included.
|
724 |
+
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
725 |
+
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
726 |
+
# (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)
|
727 |
+
)
|
728 |
+
|
729 |
+
for resp in answers:
|
730 |
+
for artifact in resp.artifacts:
|
731 |
+
if artifact.finish_reason == generation.FILTER:
|
732 |
+
warnings.warn(
|
733 |
+
"Your request activated the API's safety filters and could not be processed."
|
734 |
+
"Please modify the prompt and try again.")
|
735 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
736 |
+
img = Image.open(io.BytesIO(artifact.binary))
|
737 |
+
st.image(img)
|
738 |
+
img.save(str(artifact.seed)+ ".png") # Save our generated images with their seed number as the filename.
|
739 |
+
rx = 'Image returned'
|
740 |
+
# g_sheet_log(mytext, rx)
|
741 |
+
now = datetime.datetime.now()
|
742 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
743 |
+
csv_logs(mytext, rx, date_time)
|
744 |
+
|
745 |
+
|
746 |
+
elif ("vid_tube" in string_temp):
|
747 |
+
s = Search(mytext)
|
748 |
+
search_res = s.results
|
749 |
+
first_vid = search_res[0]
|
750 |
+
print(first_vid)
|
751 |
+
string = str(first_vid)
|
752 |
+
video_id = string[string.index('=') + 1:-1]
|
753 |
+
# print(video_id)
|
754 |
+
YoutubeURL = "https://www.youtube.com/watch?v="
|
755 |
+
OurURL = YoutubeURL + video_id
|
756 |
+
st.write(OurURL)
|
757 |
+
st_player(OurURL)
|
758 |
+
now = datetime.datetime.now()
|
759 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
760 |
+
ry = 'Youtube link and video returned'
|
761 |
+
# g_sheet_log(mytext, ry)
|
762 |
+
csv_logs(mytext, ry, date_time)
|
763 |
+
|
764 |
+
elif ("don't" in string_temp or "internet" in string_temp):
|
765 |
+
st.write('searching internet ')
|
766 |
+
search_internet(question)
|
767 |
+
# rz = 'Internet result returned'
|
768 |
+
# g_sheet_log(mytext, string_temp)
|
769 |
+
# csv_logs(mytext, rz, date_time)
|
770 |
+
|
771 |
+
else:
|
772 |
+
st.write(string_temp)
|
773 |
+
# g_sheet_log(mytext, string_temp)
|
774 |
+
now = datetime.datetime.now()
|
775 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
776 |
+
csv_logs(mytext, string_temp, date_time)
|
777 |
+
|
778 |
+
elif Input_type == 'SPEECH':
|
779 |
+
option_speech = st.selectbox(
|
780 |
+
'Choose from below: (Options for Transcription)',
|
781 |
+
('Use Microphone', 'OpenAI Whisper (Upload audio file)')
|
782 |
+
)
|
783 |
+
|
784 |
+
if option_speech == 'Use Microphone':
|
785 |
+
stt_button = Button(label="Speak", width=100)
|
786 |
+
stt_button.js_on_event("button_click", CustomJS(code="""
|
787 |
+
var recognition = new webkitSpeechRecognition();
|
788 |
+
recognition.continuous = true;
|
789 |
+
recognition.interimResults = true;
|
790 |
+
|
791 |
+
recognition.onresult = function (e) {
|
792 |
+
var value = "";
|
793 |
+
for (var i = e.resultIndex; i < e.results.length; ++i) {
|
794 |
+
if (e.results[i].isFinal) {
|
795 |
+
value += e.results[i][0].transcript;
|
796 |
+
}
|
797 |
+
}
|
798 |
+
if ( value != "") {
|
799 |
+
document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value}));
|
800 |
+
}
|
801 |
+
}
|
802 |
+
recognition.start();
|
803 |
+
"""))
|
804 |
+
|
805 |
+
result = streamlit_bokeh_events(
|
806 |
+
stt_button,
|
807 |
+
events="GET_TEXT",
|
808 |
+
key="listen",
|
809 |
+
refresh_on_update=False,
|
810 |
+
override_height=75,
|
811 |
+
debounce_time=0)
|
812 |
+
|
813 |
+
if result:
|
814 |
+
if "GET_TEXT" in result:
|
815 |
+
question = result.get("GET_TEXT")
|
816 |
+
st.text(question)
|
817 |
+
response = openai.Completion.create(
|
818 |
+
model="text-davinci-003",
|
819 |
+
prompt=f'''Your name is HyperBot and knowledge cutoff date is 2021-09, and you are not aware of any events after that time. if the
|
820 |
+
Answer to following questions is not from your knowledge base or in case of queries like date, time, weather
|
821 |
+
updates / stock updates / current affairs / news or people which requires you to have internet connection then print i don't have access to internet to answer your question,
|
822 |
+
if question is related to image or painting or drawing or diagram generation then print ipython type output function gen_draw("detailed prompt of image to be generated")
|
823 |
+
if the question is related to playing a song or video or music of a singer then print ipython type output function vid_tube("relevent search query")
|
824 |
+
if the question is related to operating home appliances then print ipython type output function home_app(" action(ON/Off),appliance(TV,Geaser,Fridge,Lights,fans,AC)") .
|
825 |
+
if question is realted to sending mail or sms then print ipython type output function messenger_app(" message of us ,messenger(email,sms)")
|
826 |
+
\nQuestion-{question}
|
827 |
+
\nAnswer -''',
|
828 |
+
temperature=0.49,
|
829 |
+
max_tokens=256,
|
830 |
+
top_p=1,
|
831 |
+
frequency_penalty=0,
|
832 |
+
presence_penalty=0
|
833 |
+
)
|
834 |
+
string_temp=response.choices[0].text
|
835 |
+
|
836 |
+
if ("gen_draw" in string_temp):
|
837 |
+
try:
|
838 |
+
try:
|
839 |
+
wget.download(openai_response(prompt))
|
840 |
+
img2 = Image.open(wget.download(openai_response(prompt)))
|
841 |
+
img2.show()
|
842 |
+
rx = 'Image returned'
|
843 |
+
now = datetime.datetime.now()
|
844 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
845 |
+
csv_logs(question, rx, date_time)
|
846 |
+
except:
|
847 |
+
urllib.request.urlretrieve(openai_response(prompt),"img_ret.png")
|
848 |
+
img = Image.open("img_ret.png")
|
849 |
+
img.show()
|
850 |
+
rx = 'Image returned'
|
851 |
+
now = datetime.datetime.now()
|
852 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
853 |
+
csv_logs(question, rx, date_time)
|
854 |
+
except:
|
855 |
+
# Set up our initial generation parameters.
|
856 |
+
answers = stability_api.generate(
|
857 |
+
prompt = mytext,
|
858 |
+
seed=992446758, # If a seed is provided, the resulting generated image will be deterministic.
|
859 |
+
# What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.
|
860 |
+
# Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.
|
861 |
+
steps=30, # Amount of inference steps performed on image generation. Defaults to 30.
|
862 |
+
cfg_scale=8.0, # Influences how strongly your generation is guided to match your prompt.
|
863 |
+
# Setting this value higher increases the strength in which it tries to match your prompt.
|
864 |
+
# Defaults to 7.0 if not specified.
|
865 |
+
width=512, # Generation width, defaults to 512 if not included.
|
866 |
+
height=512, # Generation height, defaults to 512 if not included.
|
867 |
+
samples=1, # Number of images to generate, defaults to 1 if not included.
|
868 |
+
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
869 |
+
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
870 |
+
# (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)
|
871 |
+
)
|
872 |
+
|
873 |
+
for resp in answers:
|
874 |
+
for artifact in resp.artifacts:
|
875 |
+
if artifact.finish_reason == generation.FILTER:
|
876 |
+
warnings.warn(
|
877 |
+
"Your request activated the API's safety filters and could not be processed."
|
878 |
+
"Please modify the prompt and try again.")
|
879 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
880 |
+
img = Image.open(io.BytesIO(artifact.binary))
|
881 |
+
st.image(img)
|
882 |
+
img.save(str(artifact.seed)+ ".png") # Save our generated images with their seed number as the filename.
|
883 |
+
rx = 'Image returned'
|
884 |
+
# g_sheet_log(mytext, rx)
|
885 |
+
csv_logs(question, rx, date_time)
|
886 |
+
|
887 |
+
elif ("vid_tube" in string_temp):
|
888 |
+
s = Search(question)
|
889 |
+
search_res = s.results
|
890 |
+
first_vid = search_res[0]
|
891 |
+
print(first_vid)
|
892 |
+
string = str(first_vid)
|
893 |
+
video_id = string[string.index('=') + 1:-1]
|
894 |
+
# print(video_id)
|
895 |
+
YoutubeURL = "https://www.youtube.com/watch?v="
|
896 |
+
OurURL = YoutubeURL + video_id
|
897 |
+
st.write(OurURL)
|
898 |
+
st_player(OurURL)
|
899 |
+
now = datetime.datetime.now()
|
900 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
901 |
+
ry = 'Youtube link and video returned'
|
902 |
+
# g_sheet_log(mytext, ry)
|
903 |
+
csv_logs(question, ry, date_time)
|
904 |
+
|
905 |
+
|
906 |
+
elif ("don't" in string_temp or "internet" in string_temp ):
|
907 |
+
st.write('*searching internet*')
|
908 |
+
search_internet(question)
|
909 |
+
else:
|
910 |
+
st.write(string_temp)
|
911 |
+
now = datetime.datetime.now()
|
912 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
913 |
+
csv_logs(question, string_temp, date_time)
|
914 |
+
|
915 |
+
|
916 |
+
elif option_speech == 'OpenAI Whisper (Upload audio file)':
|
917 |
+
audio_file = st.file_uploader("Upload Audio file",type=['wav', 'mp3'])
|
918 |
+
if audio_file is not None:
|
919 |
+
# file = open(audio_file, "rb")
|
920 |
+
st.audio(audio_file)
|
921 |
+
transcription = openai.Audio.transcribe("whisper-1", audio_file)
|
922 |
+
st.write(transcription["text"])
|
923 |
+
result = transcription["text"]
|
924 |
+
question = result
|
925 |
+
response = openai.Completion.create(
|
926 |
+
model="text-davinci-003",
|
927 |
+
prompt=f'''Your name is HyperBot and knowledge cutoff date is 2021-09, and you are not aware of any events after that time. if the
|
928 |
+
Answer to following questions is not from your knowledge base or in case of queries like date, time, weather
|
929 |
+
updates / stock updates / current affairs / news or people which requires you to have internet connection then print i don't have access to internet to answer your question,
|
930 |
+
if question is related to image or painting or drawing or diagram generation then print ipython type output function gen_draw("detailed prompt of image to be generated")
|
931 |
+
if the question is related to playing a song or video or music of a singer then print ipython type output function vid_tube("relevent search query")
|
932 |
+
if the question is related to operating home appliances then print ipython type output function home_app(" action(ON/Off),appliance(TV,Geaser,Fridge,Lights,fans,AC)") .
|
933 |
+
if question is realted to sending mail or sms then print ipython type output function messenger_app(" message of us ,messenger(email,sms)")
|
934 |
+
\nQuestion-{question}
|
935 |
+
\nAnswer -''',
|
936 |
+
temperature=0.49,
|
937 |
+
max_tokens=256,
|
938 |
+
top_p=1,
|
939 |
+
frequency_penalty=0,
|
940 |
+
presence_penalty=0
|
941 |
+
)
|
942 |
+
|
943 |
+
string_temp=response.choices[0].text
|
944 |
+
|
945 |
+
if ("gen_draw" in string_temp):
|
946 |
+
try:
|
947 |
+
try:
|
948 |
+
wget.download(openai_response(prompt))
|
949 |
+
img2 = Image.open(wget.download(openai_response(prompt)))
|
950 |
+
img2.show()
|
951 |
+
rx = 'Image returned'
|
952 |
+
now = datetime.datetime.now()
|
953 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
954 |
+
csv_logs(question, rx, date_time)
|
955 |
+
except:
|
956 |
+
urllib.request.urlretrieve(openai_response(prompt),"img_ret.png")
|
957 |
+
img = Image.open("img_ret.png")
|
958 |
+
img.show()
|
959 |
+
rx = 'Image returned'
|
960 |
+
now = datetime.datetime.now()
|
961 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
962 |
+
csv_logs(question, rx, date_time)
|
963 |
+
except:
|
964 |
+
# Set up our initial generation parameters.
|
965 |
+
answers = stability_api.generate(
|
966 |
+
prompt = mytext,
|
967 |
+
seed=992446758, # If a seed is provided, the resulting generated image will be deterministic.
|
968 |
+
# What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.
|
969 |
+
# Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.
|
970 |
+
steps=30, # Amount of inference steps performed on image generation. Defaults to 30.
|
971 |
+
cfg_scale=8.0, # Influences how strongly your generation is guided to match your prompt.
|
972 |
+
# Setting this value higher increases the strength in which it tries to match your prompt.
|
973 |
+
# Defaults to 7.0 if not specified.
|
974 |
+
width=512, # Generation width, defaults to 512 if not included.
|
975 |
+
height=512, # Generation height, defaults to 512 if not included.
|
976 |
+
samples=1, # Number of images to generate, defaults to 1 if not included.
|
977 |
+
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
978 |
+
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
979 |
+
# (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)
|
980 |
+
)
|
981 |
+
|
982 |
+
for resp in answers:
|
983 |
+
for artifact in resp.artifacts:
|
984 |
+
if artifact.finish_reason == generation.FILTER:
|
985 |
+
warnings.warn(
|
986 |
+
"Your request activated the API's safety filters and could not be processed."
|
987 |
+
"Please modify the prompt and try again.")
|
988 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
989 |
+
img = Image.open(io.BytesIO(artifact.binary))
|
990 |
+
st.image(img)
|
991 |
+
img.save(str(artifact.seed)+ ".png") # Save our generated images with their seed number as the filename.
|
992 |
+
rx = 'Image returned'
|
993 |
+
# g_sheet_log(mytext, rx)
|
994 |
+
csv_logs(question, rx, date_time)
|
995 |
+
|
996 |
+
|
997 |
+
elif ("vid_tube" in string_temp):
|
998 |
+
s = Search(question)
|
999 |
+
search_res = s.results
|
1000 |
+
first_vid = search_res[0]
|
1001 |
+
print(first_vid)
|
1002 |
+
string = str(first_vid)
|
1003 |
+
video_id = string[string.index('=') + 1:-1]
|
1004 |
+
# print(video_id)
|
1005 |
+
YoutubeURL = "https://www.youtube.com/watch?v="
|
1006 |
+
OurURL = YoutubeURL + video_id
|
1007 |
+
st.write(OurURL)
|
1008 |
+
st_player(OurURL)
|
1009 |
+
now = datetime.datetime.now()
|
1010 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
1011 |
+
ry = 'Youtube link and video returned'
|
1012 |
+
# g_sheet_log(mytext, ry)
|
1013 |
+
csv_logs(question, ry, date_time)
|
1014 |
+
|
1015 |
+
elif ("don't" in string_temp or "internet" in string_temp ):
|
1016 |
+
st.write('*searching internet*')
|
1017 |
+
search_internet(question)
|
1018 |
+
else:
|
1019 |
+
st.write(string_temp)
|
1020 |
+
now = datetime.datetime.now()
|
1021 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
1022 |
+
csv_logs(question, string_temp, date_time)
|
1023 |
+
|
1024 |
+
else:
|
1025 |
+
pass
|
logs.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Sl. No.,Input Prompt,Output,Date_time
|
requirements.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
stability-sdk
|
2 |
+
pytube
|
3 |
+
openai
|
4 |
+
google-search-results
|
5 |
+
accelerate
|
6 |
+
wget
|
7 |
+
bokeh==2.4.1
|
8 |
+
streamlit==1.10.0
|
9 |
+
streamlit-bokeh-events==0.1.2
|
10 |
+
streamlit-player
|
11 |
+
diffusers
|
12 |
+
transformers
|
13 |
+
scipy
|
14 |
+
Ipython
|
15 |
+
gspread
|
16 |
+
google-oauth2-tool
|
17 |
+
google-api-python-client
|
18 |
+
urllib3
|
19 |
+
Pillow
|
20 |
+
wget
|
21 |
+
pandasql
|
22 |
+
pandas
|
23 |
+
sounddevice==0.4.1
|
24 |
+
soundfile
|