Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,7 +80,6 @@
|
|
80 |
|
81 |
from time import sleep
|
82 |
import gradio as gr
|
83 |
-
import traceback
|
84 |
import requests
|
85 |
import openai
|
86 |
import random
|
@@ -88,6 +87,8 @@ import base64
|
|
88 |
import os
|
89 |
|
90 |
def function(Textbox,Textbox2, Textbox3):
|
|
|
|
|
91 |
target = os.environ.get("target")
|
92 |
target2 = os.environ.get("target2")
|
93 |
openai.api_key = target2
|
@@ -151,22 +152,15 @@ def function(Textbox,Textbox2, Textbox3):
|
|
151 |
{"role": "user", "content": i}
|
152 |
)
|
153 |
try:
|
154 |
-
# sleep(
|
155 |
-
|
156 |
-
"
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
"presence_penalty":0,
|
161 |
-
"top_p":1,
|
162 |
-
"frequency_penalty":0,
|
163 |
-
"stream":False
|
164 |
-
}).json()
|
165 |
-
reply = response['choices'][0]['message']['content']
|
166 |
messages.append({"role": "assistant", "content": reply})
|
167 |
return reply
|
168 |
-
except
|
169 |
-
print(traceback.format_exc())
|
170 |
return "Please Wait!"
|
171 |
else:
|
172 |
return "Failed"
|
@@ -181,3 +175,106 @@ iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
|
181 |
|
182 |
iface.launch()
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
from time import sleep
|
82 |
import gradio as gr
|
|
|
83 |
import requests
|
84 |
import openai
|
85 |
import random
|
|
|
87 |
import os
|
88 |
|
89 |
def function(Textbox,Textbox2, Textbox3):
|
90 |
+
openai.api_key = ''
|
91 |
+
openai.api_base = os.environ.get("base")
|
92 |
target = os.environ.get("target")
|
93 |
target2 = os.environ.get("target2")
|
94 |
openai.api_key = target2
|
|
|
152 |
{"role": "user", "content": i}
|
153 |
)
|
154 |
try:
|
155 |
+
# sleep(0.8)
|
156 |
+
chat = openai.ChatCompletion.create(
|
157 |
+
model="gpt-3.5-turbo", messages=messages
|
158 |
+
)
|
159 |
+
# reply = chat.choices[0].message.content
|
160 |
+
reply = chat.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
messages.append({"role": "assistant", "content": reply})
|
162 |
return reply
|
163 |
+
except:
|
|
|
164 |
return "Please Wait!"
|
165 |
else:
|
166 |
return "Failed"
|
|
|
175 |
|
176 |
iface.launch()
|
177 |
|
178 |
+
# from time import sleep
|
179 |
+
# import gradio as gr
|
180 |
+
# import traceback
|
181 |
+
# import requests
|
182 |
+
# import openai
|
183 |
+
# import random
|
184 |
+
# import base64
|
185 |
+
# import os
|
186 |
+
|
187 |
+
# def function(Textbox,Textbox2, Textbox3):
|
188 |
+
# target = os.environ.get("target")
|
189 |
+
# target2 = os.environ.get("target2")
|
190 |
+
# openai.api_key = target2
|
191 |
+
# content = os.environ.get("content")
|
192 |
+
# content2 = os.environ.get("content2")
|
193 |
+
# link1 = os.environ.get("link1")
|
194 |
+
# path = os.environ.get("path")
|
195 |
+
# link2 = os.environ.get("link2")
|
196 |
+
# if "/web" in Textbox.lower() or "web" in Textbox.lower():
|
197 |
+
# try:
|
198 |
+
# prompt = Textbox.replace("/web","")
|
199 |
+
# except:
|
200 |
+
# prompt = Textbox.replace("web","")
|
201 |
+
# headers = {
|
202 |
+
# "authority": link1,
|
203 |
+
# "method": "POST",
|
204 |
+
# "path": path,
|
205 |
+
# "scheme": "https",
|
206 |
+
# "accept": "application/json, text/plain, */*",
|
207 |
+
# "accept-encoding": "gzip, deflate, br",
|
208 |
+
# "accept-language": "en-US,en;q=0.9",
|
209 |
+
# "content-length": "88",
|
210 |
+
# "content-type": "application/json",
|
211 |
+
# "origin": link2,
|
212 |
+
# "referer": f"{link2}/",
|
213 |
+
# "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
214 |
+
# "sec-ch-ua-mobile": "?0",
|
215 |
+
# "sec-ch-ua-platform": '"Windows"',
|
216 |
+
# "sec-fetch-dest": "empty",
|
217 |
+
# "sec-fetch-mode": "cors",
|
218 |
+
# "sec-fetch-site": "same-site",
|
219 |
+
# "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"
|
220 |
+
# }
|
221 |
+
# href = os.environ.get("href")
|
222 |
+
# response = requests.post(href,json={
|
223 |
+
# "Body":prompt,
|
224 |
+
# "From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
|
225 |
+
# },headers=headers)
|
226 |
+
# data = response.json()
|
227 |
+
# data = data["message"]
|
228 |
+
# trigger = os.environ.get("trigger")
|
229 |
+
# if trigger in data:
|
230 |
+
# data = data.replace(trigger,"John")
|
231 |
+
# return data
|
232 |
+
# else:
|
233 |
+
# return data
|
234 |
+
# else:
|
235 |
+
# # model = os.environ.get("model")
|
236 |
+
# # hrc = os.environ.get("hrc")
|
237 |
+
# if Textbox3 == target:
|
238 |
+
# Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
239 |
+
# Textbox2 = Textbox2.split(",")
|
240 |
+
# Textbox2_edited = [x.strip() for x in Textbox2]
|
241 |
+
# Textbox2_edited = list(Textbox2_edited)
|
242 |
+
# Textbox2_edited.append(Textbox)
|
243 |
+
# messages = [
|
244 |
+
# {"role": "system", "content": content2},
|
245 |
+
# ]
|
246 |
+
# for i in Textbox2_edited:
|
247 |
+
# messages.append(
|
248 |
+
# {"role": "user", "content": i}
|
249 |
+
# )
|
250 |
+
# try:
|
251 |
+
# # sleep(1.8)
|
252 |
+
# response = requests.post(target2, json={
|
253 |
+
# "messages":messages,
|
254 |
+
# "model":"gpt-3.5-turbo-003",
|
255 |
+
# "max_tokens":"null",
|
256 |
+
# "temperature":1,
|
257 |
+
# "presence_penalty":0,
|
258 |
+
# "top_p":1,
|
259 |
+
# "frequency_penalty":0,
|
260 |
+
# "stream":False
|
261 |
+
# }).json()
|
262 |
+
# reply = response['choices'][0]['message']['content']
|
263 |
+
# messages.append({"role": "assistant", "content": reply})
|
264 |
+
# return reply
|
265 |
+
# except Exception as e:
|
266 |
+
# print(traceback.format_exc())
|
267 |
+
# return "Please Wait!"
|
268 |
+
# else:
|
269 |
+
# return "Failed"
|
270 |
+
|
271 |
+
# inputs = [
|
272 |
+
# gr.inputs.Textbox(label="Textbox",type="text"),
|
273 |
+
# gr.inputs.Textbox(label="Textbox2",type="text"),
|
274 |
+
# gr.inputs.Textbox(label="Textbox3",type="password")
|
275 |
+
# ]
|
276 |
+
|
277 |
+
# iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
278 |
+
|
279 |
+
# iface.launch()
|
280 |
+
|