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