CobaltZvc commited on
Commit
14ae94d
1 Parent(s): 86e32b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -45
app.py CHANGED
@@ -71,52 +71,149 @@ stability_api = client.StabilityInference(
71
  # stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-inpainting-v1-0 stable-inpainting-512-v2-0
72
  )
73
 
74
- def search_internet(question):
75
- params = {
76
- "q": question,
77
- "location": "Bengaluru, Karnataka, India",
78
- "hl": "hi",
79
- "gl": "in",
80
- "google_domain": "google.co.in",
81
- # "api_key": ""
82
- "api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
83
- }
84
-
85
- params = {
86
- "q": question,
87
- "location": "Bengaluru, Karnataka, India",
88
- "hl": "hi",
89
- "gl": "in",
90
- "google_domain": "google.co.in",
91
- # "api_key": ""
92
- "api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
93
- }
94
-
95
- search = GoogleSearch(params)
96
- results = search.get_dict()
97
- organic_results = results["organic_results"]
98
-
99
-
100
- snippets = ""
101
- counter = 1
102
- for item in organic_results:
103
- snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
104
- counter += 1
105
-
106
- # snippets
107
-
108
- response = openai.Completion.create(
109
- model="text-davinci-003",
110
- 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-''',
111
- temperature=0.49,
112
- max_tokens=256,
113
- top_p=1,
114
- frequency_penalty=0,
115
- presence_penalty=0)
116
 
117
- string_temp = response.choices[0].text
118
- st.write(string_temp)
119
- st.write(snippets)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  # openai.api_key = ""
122
  openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ['OPENAI_KEY']
 
71
  # stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-inpainting-v1-0 stable-inpainting-512-v2-0
72
  )
73
 
74
+ api_ls = [st.secrets("GOOGLE_API"), st.secrets("GOOGLE_API1"), st.secrets("GOOGLE_API2")]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
+ def search_internet(question):
77
+ try:
78
+ params = {
79
+ "q": question,
80
+ "location": "Bengaluru, Karnataka, India",
81
+ "hl": "hi",
82
+ "gl": "in",
83
+ "google_domain": "google.co.in",
84
+ # "api_key": ""
85
+ "api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
86
+ }
87
+
88
+ params = {
89
+ "q": question,
90
+ "location": "Bengaluru, Karnataka, India",
91
+ "hl": "hi",
92
+ "gl": "in",
93
+ "google_domain": "google.co.in",
94
+ # "api_key": ""
95
+ "api_key": st.secrets["GOOGLE_API"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
96
+ }
97
+
98
+ search = GoogleSearch(params)
99
+ results = search.get_dict()
100
+ organic_results = results["organic_results"]
101
+
102
+
103
+ snippets = ""
104
+ counter = 1
105
+ for item in organic_results:
106
+ snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
107
+ counter += 1
108
+
109
+ # snippets
110
+
111
+ response = openai.Completion.create(
112
+ model="text-davinci-003",
113
+ 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-''',
114
+ temperature=0.49,
115
+ max_tokens=256,
116
+ top_p=1,
117
+ frequency_penalty=0,
118
+ presence_penalty=0)
119
+
120
+ string_temp = response.choices[0].text
121
+ st.write(string_temp)
122
+ st.write(snippets)
123
+ except:
124
+ try:
125
+ params = {
126
+ "q": question,
127
+ "location": "Bengaluru, Karnataka, India",
128
+ "hl": "hi",
129
+ "gl": "in",
130
+ "google_domain": "google.co.in",
131
+ # "api_key": ""
132
+ "api_key": st.secrets["GOOGLE_API1"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
133
+ }
134
+
135
+ params = {
136
+ "q": question,
137
+ "location": "Bengaluru, Karnataka, India",
138
+ "hl": "hi",
139
+ "gl": "in",
140
+ "google_domain": "google.co.in",
141
+ # "api_key": ""
142
+ "api_key": st.secrets["GOOGLE_API1"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
143
+ }
144
+
145
+ search = GoogleSearch(params)
146
+ results = search.get_dict()
147
+ organic_results = results["organic_results"]
148
+
149
+
150
+ snippets = ""
151
+ counter = 1
152
+ for item in organic_results:
153
+ snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
154
+ counter += 1
155
+
156
+ # snippets
157
+
158
+ response = openai.Completion.create(
159
+ model="text-davinci-003",
160
+ 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-''',
161
+ temperature=0.49,
162
+ max_tokens=256,
163
+ top_p=1,
164
+ frequency_penalty=0,
165
+ presence_penalty=0)
166
+
167
+ string_temp = response.choices[0].text
168
+ st.write(string_temp)
169
+ st.write(snippets)
170
+ except:
171
+ params = {
172
+ "q": question,
173
+ "location": "Bengaluru, Karnataka, India",
174
+ "hl": "hi",
175
+ "gl": "in",
176
+ "google_domain": "google.co.in",
177
+ # "api_key": ""
178
+ "api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
179
+ }
180
+
181
+ params = {
182
+ "q": question,
183
+ "location": "Bengaluru, Karnataka, India",
184
+ "hl": "hi",
185
+ "gl": "in",
186
+ "google_domain": "google.co.in",
187
+ # "api_key": ""
188
+ "api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
189
+ }
190
+
191
+ search = GoogleSearch(params)
192
+ results = search.get_dict()
193
+ organic_results = results["organic_results"]
194
+
195
+
196
+ snippets = ""
197
+ counter = 1
198
+ for item in organic_results:
199
+ snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
200
+ counter += 1
201
+
202
+ # snippets
203
+
204
+ response = openai.Completion.create(
205
+ model="text-davinci-003",
206
+ 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-''',
207
+ temperature=0.49,
208
+ max_tokens=256,
209
+ top_p=1,
210
+ frequency_penalty=0,
211
+ presence_penalty=0)
212
+
213
+ string_temp = response.choices[0].text
214
+ st.write(string_temp)
215
+ st.write(snippets)
216
+
217
 
218
  # openai.api_key = ""
219
  openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ['OPENAI_KEY']