Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -718,59 +718,60 @@ elif Usage == 'Random Questions':
|
|
718 |
result = transcription["text"]
|
719 |
question = result
|
720 |
response = openai.Completion.create(
|
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 |
# except:
|
776 |
# pass
|
|
|
718 |
result = transcription["text"]
|
719 |
question = result
|
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 |
+
|
736 |
+
string_temp=response.choices[0].text
|
737 |
+
|
738 |
+
if ("gen_draw" in string_temp):
|
739 |
+
st.write('*image is being generated please wait..* ')
|
740 |
+
def extract_image_description(input_string):
|
741 |
+
return input_string.split('gen_draw("')[1].split('")')[0]
|
742 |
+
prompt=extract_image_description(string_temp)
|
743 |
+
# model_id = "CompVis/stable-diffusion-v1-4"
|
744 |
+
model_id='runwayml/stable-diffusion-v1-5'
|
745 |
+
device = "cuda"
|
746 |
+
|
747 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
748 |
+
pipe = pipe.to(device)
|
749 |
+
|
750 |
+
# prompt = "a photo of an astronaut riding a horse on mars"
|
751 |
+
image = pipe(prompt).images[0]
|
752 |
+
|
753 |
+
image.save("astronaut_rides_horse.png")
|
754 |
+
st.image(image)
|
755 |
+
# image
|
756 |
+
|
757 |
+
elif ("vid_tube" in string_temp):
|
758 |
+
s = Search(question)
|
759 |
+
search_res = s.results
|
760 |
+
first_vid = search_res[0]
|
761 |
+
print(first_vid)
|
762 |
+
string = str(first_vid)
|
763 |
+
video_id = string[string.index('=') + 1:-1]
|
764 |
+
# print(video_id)
|
765 |
+
YoutubeURL = "https://www.youtube.com/watch?v="
|
766 |
+
OurURL = YoutubeURL + video_id
|
767 |
+
st.write(OurURL)
|
768 |
+
st_player(OurURL)
|
769 |
+
|
770 |
+
elif ("don't" in string_temp or "internet" in string_temp ):
|
771 |
+
st.write('*searching internet*')
|
772 |
+
search_internet(question)
|
773 |
+
else:
|
774 |
+
st.write(string_temp)
|
775 |
|
776 |
# except:
|
777 |
# pass
|