Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -645,61 +645,61 @@ elif Usage == 'Random Questions':
|
|
| 645 |
|
| 646 |
if result:
|
| 647 |
if "GET_TEXT" in result:
|
| 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 |
|
|
|
|
| 645 |
|
| 646 |
if result:
|
| 647 |
if "GET_TEXT" in result:
|
| 648 |
+
question = result.get("GET_TEXT")
|
| 649 |
+
response = openai.Completion.create(
|
| 650 |
+
model="gpt-3.5-turbo",
|
| 651 |
+
prompt=f'''Your knowledge cutoff is 2021-09, and it is not aware of any events after that time. if the
|
| 652 |
+
Answer to following questions is not from your knowledge base or in case of queries like weather
|
| 653 |
+
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,
|
| 654 |
+
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")
|
| 655 |
+
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")
|
| 656 |
+
\nQuestion-{question}
|
| 657 |
+
\nAnswer -''',
|
| 658 |
+
temperature=0.49,
|
| 659 |
+
max_tokens=256,
|
| 660 |
+
top_p=1,
|
| 661 |
+
frequency_penalty=0,
|
| 662 |
+
presence_penalty=0
|
| 663 |
+
)
|
| 664 |
+
string_temp=response.choices[0].text
|
| 665 |
+
|
| 666 |
+
if ("gen_draw" in string_temp):
|
| 667 |
+
st.write('*image is being generated please wait..* ')
|
| 668 |
+
def extract_image_description(input_string):
|
| 669 |
+
return input_string.split('gen_draw("')[1].split('")')[0]
|
| 670 |
+
prompt=extract_image_description(string_temp)
|
| 671 |
+
# model_id = "CompVis/stable-diffusion-v1-4"
|
| 672 |
+
model_id='runwayml/stable-diffusion-v1-5'
|
| 673 |
+
device = "cuda"
|
| 674 |
+
|
| 675 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 676 |
+
pipe = pipe.to(device)
|
| 677 |
+
|
| 678 |
+
# prompt = "a photo of an astronaut riding a horse on mars"
|
| 679 |
+
image = pipe(prompt).images[0]
|
| 680 |
+
|
| 681 |
+
image.save("astronaut_rides_horse.png")
|
| 682 |
+
st.image(image)
|
| 683 |
+
# image
|
| 684 |
+
|
| 685 |
+
elif ("vid_tube" in string_temp):
|
| 686 |
+
s = Search(question)
|
| 687 |
+
search_res = s.results
|
| 688 |
+
first_vid = search_res[0]
|
| 689 |
+
print(first_vid)
|
| 690 |
+
string = str(first_vid)
|
| 691 |
+
video_id = string[string.index('=') + 1:-1]
|
| 692 |
+
# print(video_id)
|
| 693 |
+
YoutubeURL = "https://www.youtube.com/watch?v="
|
| 694 |
+
OurURL = YoutubeURL + video_id
|
| 695 |
+
st.write(OurURL)
|
| 696 |
+
st_player(OurURL)
|
| 697 |
+
|
| 698 |
+
elif ("don't" in string_temp or "internet" in string_temp ):
|
| 699 |
+
st.write('*searching internet*')
|
| 700 |
+
search_internet(question)
|
| 701 |
+
else:
|
| 702 |
+
st.write(string_temp)
|
| 703 |
|
| 704 |
|
| 705 |
|