CobaltZvc commited on
Commit
639b1ac
1 Parent(s): b5f653e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -53
app.py CHANGED
@@ -718,59 +718,60 @@ elif Usage == 'Random Questions':
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
- 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
 
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