Kvikontent commited on
Commit
cb64069
·
verified ·
1 Parent(s): 8af6028

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import io
4
+ import PIL
5
+ import freeGPT
6
+
7
+ hf_token = os.environ.get("API_TOKEN")
8
+ API_URL = "https://api-inference.huggingface.co/models/Lykon/dreamshaper-xl-v2-turbo"
9
+ headers = {"Authorization": f"Bearer {hf_token}"}
10
+
11
+ st.title("🌎 AI Browser")
12
+ st.write("Browser that gives results using ai")
13
+ prompt = st.input_text("Search something", placeholder="Enter search query")
14
+ search_btn = st.button("Search")
15
+ results = st.container("Results")
16
+ texts, images = st.tabs(["All", "Images"])
17
+
18
+ def query(payload):
19
+ response = requests.post(API_URL, headers=headers, json=payload)
20
+ return response.content
21
+
22
+ def generate_image(prompt):
23
+ image_bytes = query({
24
+ "inputs": prompt,
25
+ })
26
+ image = Image.open(io.BytesIO(image_bytes))
27
+ return image
28
+
29
+ if search_btn:
30
+ prompt1 = prompt + ". Give short answer to this question"
31
+ prompt2 = prompt + ". Give short funny answer to this question"
32
+ prompt3 = prompt + ". Give short documental answer to this question"
33
+
34
+ result1 = Client.create_completion("gpt3", prompt1)
35
+ result2 = Client.create_completion("gpt3", prompt2)
36
+ result3 = Client.create_completion("gpt3", prompt3)
37
+ result4 = Client.create_completion("gpt3", prompt4)
38
+ result5 = Client.create_completion("gpt3", prompt5)
39
+ result6 = Client.create_completion("gpt3", prompt6)
40
+
41
+ imageresult1 = generate_image(prompt + ". Create image of this in realistic style")
42
+ imageresult2 = generate_image(prompt + ". Create image of this in anime style")
43
+ imageresult3 = generate_image(prompt + ". Create image of this in black and white style")
44
+ imageresult4 = generate_image(prompt + ". Create image of this in photo style")
45
+ imageresult5 = generate_image(prompt + ". Create image of this in style of iphone low quality photo")
46
+ imageresult6 = generate_image(prompt + ". Create image of this in cinemtic style")
47
+ imageresult7 = generate_image(prompt + ". Create image of this in unreal engine style")
48
+ imageresult8 = generate_image(prompt + ". Create image of this in google style")
49
+ imageresult9 = generate_image(prompt + ". Create image of this in russia style")
50
+ imageresult10 = generate_image(prompt + ". Create image of this in chinese style")
51
+ imageresult11 = generate_image(prompt + ". Create image of this in style of sumsung low quality photo")
52
+ imageresult12 = generate_image(prompt + ". Create image of this in romantic style")
53
+
54
+ with texts:
55
+ st.write("We found these results on your query: ")
56
+ st.header(result1.split()[0], divider='rainbow')
57
+ st.text(result1)
58
+ st.header(result2.split()[0], divider='rainbow')
59
+ st.text(result2)
60
+ st.header(result3.split()[0], divider='rainbow')
61
+ st.text(result3)
62
+ st.header(result4.split()[0], divider='rainbow')
63
+ st.text(result4)
64
+ st.header(result5.split()[0], divider='rainbow')
65
+ st.text(result5)
66
+ st.header(result6.split()[0], divider='rainbow')
67
+ st.text(result6)
68
+ st.caption("That's the end!")
69
+
70
+ with images:
71
+ im1, im2, im3 = st.column(3)
72
+ im4, im5, im6 = st.column(3)
73
+ im9, im8, im7 = st.column(3)
74
+ im10, im11, im12 = st.column(3)
75
+
76
+ st.write("We found some images on your query: ")
77
+ with im1:
78
+ st.image(imageresult1)
79
+ with im2:
80
+ st.image(imageresult2)
81
+ with im3:
82
+ st.image(imageresult3)
83
+ with im4:
84
+ st.image(imageresult4)
85
+ with im5:
86
+ st.image(imageresult5)
87
+ with im6:
88
+ st.image(imageresult6)
89
+ with im7:
90
+ st.image(imageresult7)
91
+ with im8:
92
+ st.image(imageresult8)
93
+ with im9:
94
+ st.image(imageresult9)
95
+ with im10:
96
+ st.image(imageresult10)
97
+ with im11:
98
+ st.image(imageresult11)
99
+ with im12:
100
+ st.image(imageresult12)