Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ def gpt3(texts):
|
|
42 |
# openai.api_key = os.environ["Secret"]
|
43 |
openai.api_key = st.secrets['OPENAI_KEY'] #'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'#'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' #'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'
|
44 |
response = openai.Completion.create(
|
45 |
-
engine="
|
46 |
prompt= texts,
|
47 |
temperature=temp,
|
48 |
max_tokens=750,
|
@@ -110,7 +110,7 @@ def search_internet(question):
|
|
110 |
# snippets
|
111 |
|
112 |
response = openai.Completion.create(
|
113 |
-
model="
|
114 |
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-''',
|
115 |
temperature=0.49,
|
116 |
max_tokens=256,
|
@@ -157,7 +157,7 @@ def search_internet(question):
|
|
157 |
# snippets
|
158 |
|
159 |
response = openai.Completion.create(
|
160 |
-
model="
|
161 |
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-''',
|
162 |
temperature=0.49,
|
163 |
max_tokens=256,
|
@@ -203,7 +203,7 @@ def search_internet(question):
|
|
203 |
# snippets
|
204 |
|
205 |
response = openai.Completion.create(
|
206 |
-
model="
|
207 |
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-''',
|
208 |
temperature=0.49,
|
209 |
max_tokens=256,
|
@@ -386,7 +386,7 @@ if Usage == 'Questions based on custom CSV data':
|
|
386 |
|
387 |
if len(gr_prompt) > 4097:
|
388 |
st.write('OVERWHELMING DATA!!! You have given me more than 4097 tokens! ^_^')
|
389 |
-
st.write('As of today, the NLP model text-davinci-003 that I run on takes in inputs that have less than 4097 tokens. Kindly retry ^_^')
|
390 |
|
391 |
elif len(result_tab2.columns) < 2:
|
392 |
st.write("I need more data to conduct analysis and provide visualizations for you... ^_^")
|
@@ -394,7 +394,7 @@ if Usage == 'Questions based on custom CSV data':
|
|
394 |
else:
|
395 |
st.success("Plotting...")
|
396 |
response_graph = openai.Completion.create(
|
397 |
-
engine="
|
398 |
prompt = gr_prompt,
|
399 |
max_tokens=1024,
|
400 |
n=1,
|
@@ -462,7 +462,7 @@ if Usage == 'Questions based on custom CSV data':
|
|
462 |
else:
|
463 |
st.success("Plotting...")
|
464 |
response_graph = openai.Completion.create(
|
465 |
-
engine="
|
466 |
prompt = gr_prompt,
|
467 |
max_tokens=1024,
|
468 |
n=1,
|
@@ -502,7 +502,7 @@ elif Usage == 'Random Questions':
|
|
502 |
if st.button("SUBMIT"):
|
503 |
question=mytext
|
504 |
response = openai.Completion.create(
|
505 |
-
model="
|
506 |
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
|
507 |
Answer to following questions is not from your knowledge base or in case of queries like weather
|
508 |
updates / stock updates / current news or people which requires you to have internet connection then print i don't have access to internet to answer your question,
|
@@ -631,7 +631,7 @@ elif Usage == 'Random Questions':
|
|
631 |
|
632 |
question = result
|
633 |
response = openai.Completion.create(
|
634 |
-
model="
|
635 |
prompt=f'''Your knowledge cutoff is 2021-09, and it is not aware of any events after that time. if the
|
636 |
Answer to following questions is not from your knowledge base or in case of queries like weather
|
637 |
updates / stock updates / current news Etc which requires you to have internet connection then print i don't have access to internet to answer your question,
|
@@ -686,90 +686,6 @@ elif Usage == 'Random Questions':
|
|
686 |
st.write(string_temp)
|
687 |
|
688 |
except:
|
689 |
-
|
690 |
-
stt_button.js_on_event("button_click", CustomJS(code="""
|
691 |
-
var recognition = new webkitSpeechRecognition();
|
692 |
-
recognition.continuous = true;
|
693 |
-
recognition.interimResults = true;
|
694 |
-
recognition.onresult = function (e) {
|
695 |
-
var value = "";
|
696 |
-
for (var i = e.resultIndex; i < e.results.length; ++i) {
|
697 |
-
if (e.results[i].isFinal) {
|
698 |
-
value += e.results[i][0].transcript;
|
699 |
-
}
|
700 |
-
}
|
701 |
-
if ( value != "") {
|
702 |
-
document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value}));
|
703 |
-
}
|
704 |
-
}
|
705 |
-
recognition.start();
|
706 |
-
"""))
|
707 |
-
|
708 |
-
result = streamlit_bokeh_events(
|
709 |
-
stt_button,
|
710 |
-
events="GET_TEXT",
|
711 |
-
key="listen",
|
712 |
-
refresh_on_update=False,
|
713 |
-
override_height=75,
|
714 |
-
debounce_time=0)
|
715 |
-
|
716 |
-
if result:
|
717 |
-
if "GET_TEXT" in result:
|
718 |
-
st.write(result.get("GET_TEXT"))
|
719 |
-
question = result.get("GET_TEXT")
|
720 |
-
response = openai.Completion.create(
|
721 |
-
model="text-davinci-003",
|
722 |
-
prompt=f'''Your knowledge cutoff is 2021-09, and it is not aware of any events after that time. if the
|
723 |
-
Answer to following questions is not from your knowledge base or in case of queries like weather
|
724 |
-
updates / stock updates / current news Etc which requires you to have internet connection then print i don't have access to internet to answer your question,
|
725 |
-
if question is related to image or painting or drawing generation then print ipython type output function gen_draw("detailed prompt of image to be generated")
|
726 |
-
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")
|
727 |
-
\nQuestion-{question}
|
728 |
-
\nAnswer -''',
|
729 |
-
temperature=0.49,
|
730 |
-
max_tokens=256,
|
731 |
-
top_p=1,
|
732 |
-
frequency_penalty=0,
|
733 |
-
presence_penalty=0
|
734 |
-
)
|
735 |
-
string_temp=response.choices[0].text
|
736 |
-
|
737 |
-
if ("gen_draw" in string_temp):
|
738 |
-
st.write('*image is being generated please wait..* ')
|
739 |
-
def extract_image_description(input_string):
|
740 |
-
return input_string.split('gen_draw("')[1].split('")')[0]
|
741 |
-
prompt=extract_image_description(string_temp)
|
742 |
-
# model_id = "CompVis/stable-diffusion-v1-4"
|
743 |
-
model_id='runwayml/stable-diffusion-v1-5'
|
744 |
-
device = "cuda"
|
745 |
-
|
746 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
747 |
-
pipe = pipe.to(device)
|
748 |
-
|
749 |
-
# prompt = "a photo of an astronaut riding a horse on mars"
|
750 |
-
image = pipe(prompt).images[0]
|
751 |
-
|
752 |
-
image.save("astronaut_rides_horse.png")
|
753 |
-
st.image(image)
|
754 |
-
# image
|
755 |
-
|
756 |
-
elif ("vid_tube" in string_temp):
|
757 |
-
s = Search(question)
|
758 |
-
search_res = s.results
|
759 |
-
first_vid = search_res[0]
|
760 |
-
print(first_vid)
|
761 |
-
string = str(first_vid)
|
762 |
-
video_id = string[string.index('=') + 1:-1]
|
763 |
-
# print(video_id)
|
764 |
-
YoutubeURL = "https://www.youtube.com/watch?v="
|
765 |
-
OurURL = YoutubeURL + video_id
|
766 |
-
st.write(OurURL)
|
767 |
-
st_player(OurURL)
|
768 |
-
|
769 |
-
elif ("don't" in string_temp or "internet" in string_temp ):
|
770 |
-
st.write('*searching internet*')
|
771 |
-
search_internet(question)
|
772 |
-
else:
|
773 |
-
st.write(string_temp)
|
774 |
else:
|
775 |
pass
|
|
|
42 |
# openai.api_key = os.environ["Secret"]
|
43 |
openai.api_key = st.secrets['OPENAI_KEY'] #'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'#'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' #'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'
|
44 |
response = openai.Completion.create(
|
45 |
+
engine="gpt-3.5-turbo",
|
46 |
prompt= texts,
|
47 |
temperature=temp,
|
48 |
max_tokens=750,
|
|
|
110 |
# snippets
|
111 |
|
112 |
response = openai.Completion.create(
|
113 |
+
model="gpt-3.5-turbo",
|
114 |
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-''',
|
115 |
temperature=0.49,
|
116 |
max_tokens=256,
|
|
|
157 |
# snippets
|
158 |
|
159 |
response = openai.Completion.create(
|
160 |
+
model="gpt-3.5-turbo",
|
161 |
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-''',
|
162 |
temperature=0.49,
|
163 |
max_tokens=256,
|
|
|
203 |
# snippets
|
204 |
|
205 |
response = openai.Completion.create(
|
206 |
+
model="gpt-3.5-turbo",
|
207 |
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-''',
|
208 |
temperature=0.49,
|
209 |
max_tokens=256,
|
|
|
386 |
|
387 |
if len(gr_prompt) > 4097:
|
388 |
st.write('OVERWHELMING DATA!!! You have given me more than 4097 tokens! ^_^')
|
389 |
+
st.write('As of today, the NLP model text-davinci-003/gpt-3.5-turbo that I run on takes in inputs that have less than 4097 tokens. Kindly retry ^_^')
|
390 |
|
391 |
elif len(result_tab2.columns) < 2:
|
392 |
st.write("I need more data to conduct analysis and provide visualizations for you... ^_^")
|
|
|
394 |
else:
|
395 |
st.success("Plotting...")
|
396 |
response_graph = openai.Completion.create(
|
397 |
+
engine="gpt-3.5-turbo",
|
398 |
prompt = gr_prompt,
|
399 |
max_tokens=1024,
|
400 |
n=1,
|
|
|
462 |
else:
|
463 |
st.success("Plotting...")
|
464 |
response_graph = openai.Completion.create(
|
465 |
+
engine="gpt-3.5-turbo",
|
466 |
prompt = gr_prompt,
|
467 |
max_tokens=1024,
|
468 |
n=1,
|
|
|
502 |
if st.button("SUBMIT"):
|
503 |
question=mytext
|
504 |
response = openai.Completion.create(
|
505 |
+
model="gpt-3.5-turbo",
|
506 |
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
|
507 |
Answer to following questions is not from your knowledge base or in case of queries like weather
|
508 |
updates / stock updates / current news or people which requires you to have internet connection then print i don't have access to internet to answer your question,
|
|
|
631 |
|
632 |
question = result
|
633 |
response = openai.Completion.create(
|
634 |
+
model="gpt-3.5-turbo",
|
635 |
prompt=f'''Your knowledge cutoff is 2021-09, and it is not aware of any events after that time. if the
|
636 |
Answer to following questions is not from your knowledge base or in case of queries like weather
|
637 |
updates / stock updates / current news Etc which requires you to have internet connection then print i don't have access to internet to answer your question,
|
|
|
686 |
st.write(string_temp)
|
687 |
|
688 |
except:
|
689 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
else:
|
691 |
pass
|