Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,6 +78,101 @@
|
|
78 |
|
79 |
# iface.launch()
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# from time import sleep
|
82 |
# import gradio as gr
|
83 |
# import traceback
|
@@ -178,100 +273,100 @@
|
|
178 |
|
179 |
# iface.launch()
|
180 |
|
181 |
-
from time import sleep
|
182 |
-
import gradio as gr
|
183 |
-
import traceback
|
184 |
-
import requests
|
185 |
-
import openai
|
186 |
-
import random
|
187 |
-
import base64
|
188 |
-
import json
|
189 |
-
import os
|
190 |
|
191 |
-
def function(Textbox,Textbox2, Textbox3, Textbox4):
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
|
265 |
-
inputs = [
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
]
|
271 |
|
272 |
-
iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
273 |
|
274 |
-
iface.launch()
|
275 |
|
276 |
# from time import sleep
|
277 |
# import gradio as gr
|
|
|
78 |
|
79 |
# iface.launch()
|
80 |
|
81 |
+
from time import sleep
|
82 |
+
import gradio as gr
|
83 |
+
import requests
|
84 |
+
import openai
|
85 |
+
import random
|
86 |
+
import base64
|
87 |
+
import os
|
88 |
+
|
89 |
+
def function(Textbox,Textbox2,Textbox3):
|
90 |
+
target = os.environ.get("target")
|
91 |
+
target2 = os.environ.get("target2")
|
92 |
+
openai.api_key = target2
|
93 |
+
openai.api_base = base
|
94 |
+
content = os.environ.get("content")
|
95 |
+
link1 = os.environ.get("link1")
|
96 |
+
path = os.environ.get("path")
|
97 |
+
link2 = os.environ.get("link2")
|
98 |
+
if "/web" in Textbox.lower() or "web" in Textbox.lower():
|
99 |
+
try:
|
100 |
+
prompt = Textbox.replace("/web","")
|
101 |
+
except:
|
102 |
+
prompt = Textbox.replace("web","")
|
103 |
+
headers = {
|
104 |
+
"authority": link1,
|
105 |
+
"method": "POST",
|
106 |
+
"path": path,
|
107 |
+
"scheme": "https",
|
108 |
+
"accept": "application/json, text/plain, */*",
|
109 |
+
"accept-encoding": "gzip, deflate, br",
|
110 |
+
"accept-language": "en-US,en;q=0.9",
|
111 |
+
"content-length": "88",
|
112 |
+
"content-type": "application/json",
|
113 |
+
"origin": link2,
|
114 |
+
"referer": f"{link2}/",
|
115 |
+
"sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
116 |
+
"sec-ch-ua-mobile": "?0",
|
117 |
+
"sec-ch-ua-platform": '"Windows"',
|
118 |
+
"sec-fetch-dest": "empty",
|
119 |
+
"sec-fetch-mode": "cors",
|
120 |
+
"sec-fetch-site": "same-site",
|
121 |
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
|
122 |
+
}
|
123 |
+
href = os.environ.get("href")
|
124 |
+
response = requests.post(href,json={
|
125 |
+
"Body":prompt,
|
126 |
+
"From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
|
127 |
+
},headers=headers)
|
128 |
+
data = response.json()
|
129 |
+
data = data["message"]
|
130 |
+
trigger = os.environ.get("trigger")
|
131 |
+
if trigger in data:
|
132 |
+
data = data.replace(trigger,"John")
|
133 |
+
return data
|
134 |
+
else:
|
135 |
+
return data
|
136 |
+
else:
|
137 |
+
# model = os.environ.get("model")
|
138 |
+
# hrc = os.environ.get("hrc")
|
139 |
+
if Textbox3 == target:
|
140 |
+
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
141 |
+
Textbox2 = Textbox2.split(",")
|
142 |
+
Textbox2_edited = [x.strip() for x in Textbox2]
|
143 |
+
Textbox2_edited = list(Textbox2_edited)
|
144 |
+
Textbox2_edited.append(Textbox)
|
145 |
+
messages = [
|
146 |
+
{"role": "system", "content": content},
|
147 |
+
]
|
148 |
+
for i in Textbox2_edited:
|
149 |
+
messages.append(
|
150 |
+
{"role": "user", "content": i}
|
151 |
+
)
|
152 |
+
try:
|
153 |
+
sleep(0.8)
|
154 |
+
chat = openai.ChatCompletion.create(
|
155 |
+
model="gpt-3.5-turbo", messages=messages
|
156 |
+
)
|
157 |
+
print(messages)
|
158 |
+
reply = chat.choices[0].message.content
|
159 |
+
messages.append({"role": "assistant", "content": reply})
|
160 |
+
return reply
|
161 |
+
except:
|
162 |
+
return "Please Wait!"
|
163 |
+
else:
|
164 |
+
return "Failed"
|
165 |
+
|
166 |
+
inputs = [
|
167 |
+
gr.inputs.Textbox(label="Textbox",type="text"),
|
168 |
+
gr.inputs.Textbox(label="Textbox2",type="text"),
|
169 |
+
gr.inputs.Textbox(label="Textbox3",type="password")
|
170 |
+
]
|
171 |
+
|
172 |
+
iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
173 |
+
|
174 |
+
iface.launch()
|
175 |
+
|
176 |
# from time import sleep
|
177 |
# import gradio as gr
|
178 |
# import traceback
|
|
|
273 |
|
274 |
# iface.launch()
|
275 |
|
276 |
+
# from time import sleep
|
277 |
+
# import gradio as gr
|
278 |
+
# import traceback
|
279 |
+
# import requests
|
280 |
+
# import openai
|
281 |
+
# import random
|
282 |
+
# import base64
|
283 |
+
# import json
|
284 |
+
# import os
|
285 |
|
286 |
+
# def function(Textbox,Textbox2, Textbox3, Textbox4):
|
287 |
+
# target = os.environ.get("target")
|
288 |
+
# target2 = os.environ.get("target2")
|
289 |
+
# content = os.environ.get("content")
|
290 |
+
# content2 = os.environ.get("content2")
|
291 |
+
# auth_key = os.environ.get("auth_key")
|
292 |
+
# link1 = os.environ.get("link1")
|
293 |
+
# path = os.environ.get("path")
|
294 |
+
# link2 = os.environ.get("link2")
|
295 |
+
# if "/web" in Textbox.lower() or "web" in Textbox.lower():
|
296 |
+
# try:
|
297 |
+
# prompt = Textbox.replace("/web","")
|
298 |
+
# except:
|
299 |
+
# prompt = Textbox.replace("web","")
|
300 |
+
# headers = {
|
301 |
+
# "authority": link1,
|
302 |
+
# "method": "POST",
|
303 |
+
# "path": path,
|
304 |
+
# "scheme": "https",
|
305 |
+
# "accept": "application/json, text/plain, */*",
|
306 |
+
# "accept-encoding": "gzip, deflate, br",
|
307 |
+
# "accept-language": "en-US,en;q=0.9",
|
308 |
+
# "content-length": "88",
|
309 |
+
# "content-type": "application/json",
|
310 |
+
# "origin": link2,
|
311 |
+
# "referer": f"{link2}/",
|
312 |
+
# "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
313 |
+
# "sec-ch-ua-mobile": "?0",
|
314 |
+
# "sec-ch-ua-platform": '"Windows"',
|
315 |
+
# "sec-fetch-dest": "empty",
|
316 |
+
# "sec-fetch-mode": "cors",
|
317 |
+
# "sec-fetch-site": "same-site",
|
318 |
+
# "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
|
319 |
+
# }
|
320 |
+
# href = os.environ.get("href")
|
321 |
+
# response = requests.post(href,json={
|
322 |
+
# "Body":prompt,
|
323 |
+
# "From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
|
324 |
+
# },headers=headers)
|
325 |
+
# data = response.json()
|
326 |
+
# data = data["message"]
|
327 |
+
# trigger = os.environ.get("trigger")
|
328 |
+
# if trigger in data:
|
329 |
+
# data = data.replace(trigger,"John")
|
330 |
+
# return data
|
331 |
+
# else:
|
332 |
+
# return data
|
333 |
+
# else:
|
334 |
+
# # model = os.environ.get("model")
|
335 |
+
# # hrc = os.environ.get("hrc")
|
336 |
+
# if Textbox3 == target:
|
337 |
+
# try:
|
338 |
+
# # sleep(0.8)
|
339 |
+
# # headers = {
|
340 |
+
# # "Authorization": f"Bearer {auth_key}"
|
341 |
+
# # }
|
342 |
+
# response = requests.post(target2, headers={
|
343 |
+
# "Content-Type": "application/json"
|
344 |
+
# }, data=json.dumps({
|
345 |
+
# "text": Textbox,
|
346 |
+
# "key": auth_key,
|
347 |
+
# "playerId": Textbox4,
|
348 |
+
# "speak": False
|
349 |
+
# }))
|
350 |
+
# # reply = response['choices'][0]['message']['content']
|
351 |
+
# response = response.json()
|
352 |
+
# reply = response["output"]["text"]
|
353 |
+
# return reply
|
354 |
+
# except Exception as e:
|
355 |
+
# print(traceback.format_exc())
|
356 |
+
# return "Please Wait!"
|
357 |
+
# else:
|
358 |
+
# return "Failed"
|
359 |
|
360 |
+
# inputs = [
|
361 |
+
# gr.inputs.Textbox(label="Textbox",type="text"),
|
362 |
+
# gr.inputs.Textbox(label="Textbox2",type="text"),
|
363 |
+
# gr.inputs.Textbox(label="Textbox3",type="password"),
|
364 |
+
# gr.inputs.Textbox(label="Textbox4",type="text")
|
365 |
+
# ]
|
366 |
|
367 |
+
# iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
368 |
|
369 |
+
# iface.launch()
|
370 |
|
371 |
# from time import sleep
|
372 |
# import gradio as gr
|