Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,117 +78,22 @@
|
|
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 |
-
# 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
|
95 |
-
# content = os.environ.get("content")
|
96 |
-
# content2 = os.environ.get("content2")
|
97 |
-
# link1 = os.environ.get("link1")
|
98 |
-
# path = os.environ.get("path")
|
99 |
-
# link2 = os.environ.get("link2")
|
100 |
-
# if "/web" in Textbox.lower() or "web" in Textbox.lower():
|
101 |
-
# try:
|
102 |
-
# prompt = Textbox.replace("/web","")
|
103 |
-
# except:
|
104 |
-
# prompt = Textbox.replace("web","")
|
105 |
-
# headers = {
|
106 |
-
# "authority": link1,
|
107 |
-
# "method": "POST",
|
108 |
-
# "path": path,
|
109 |
-
# "scheme": "https",
|
110 |
-
# "accept": "application/json, text/plain, */*",
|
111 |
-
# "accept-encoding": "gzip, deflate, br",
|
112 |
-
# "accept-language": "en-US,en;q=0.9",
|
113 |
-
# "content-length": "88",
|
114 |
-
# "content-type": "application/json",
|
115 |
-
# "origin": link2,
|
116 |
-
# "referer": f"{link2}/",
|
117 |
-
# "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
118 |
-
# "sec-ch-ua-mobile": "?0",
|
119 |
-
# "sec-ch-ua-platform": '"Windows"',
|
120 |
-
# "sec-fetch-dest": "empty",
|
121 |
-
# "sec-fetch-mode": "cors",
|
122 |
-
# "sec-fetch-site": "same-site",
|
123 |
-
# "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"
|
124 |
-
# }
|
125 |
-
# href = os.environ.get("href")
|
126 |
-
# response = requests.post(href,json={
|
127 |
-
# "Body":prompt,
|
128 |
-
# "From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
|
129 |
-
# },headers=headers)
|
130 |
-
# data = response.json()
|
131 |
-
# data = data["message"]
|
132 |
-
# trigger = os.environ.get("trigger")
|
133 |
-
# if trigger in data:
|
134 |
-
# data = data.replace(trigger,"John")
|
135 |
-
# return data
|
136 |
-
# else:
|
137 |
-
# return data
|
138 |
-
# else:
|
139 |
-
# # model = os.environ.get("model")
|
140 |
-
# # hrc = os.environ.get("hrc")
|
141 |
-
# if Textbox3 == target:
|
142 |
-
# Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
143 |
-
# Textbox2 = Textbox2.split(",")
|
144 |
-
# Textbox2_edited = [x.strip() for x in Textbox2]
|
145 |
-
# Textbox2_edited = list(Textbox2_edited)
|
146 |
-
# Textbox2_edited.append(Textbox)
|
147 |
-
# messages = [
|
148 |
-
# {"role": "system", "content": content2},
|
149 |
-
# ]
|
150 |
-
# for i in Textbox2_edited:
|
151 |
-
# messages.append(
|
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"
|
167 |
-
|
168 |
-
# inputs = [
|
169 |
-
# gr.inputs.Textbox(label="Textbox",type="text"),
|
170 |
-
# gr.inputs.Textbox(label="Textbox2",type="text"),
|
171 |
-
# gr.inputs.Textbox(label="Textbox3",type="password")
|
172 |
-
# ]
|
173 |
-
|
174 |
-
# iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
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 |
link1 = os.environ.get("link1")
|
193 |
path = os.environ.get("path")
|
194 |
link2 = os.environ.get("link2")
|
@@ -240,23 +145,31 @@ def function(Textbox,Textbox2,Textbox3):
|
|
240 |
Textbox2_edited = list(Textbox2_edited)
|
241 |
Textbox2_edited.append(Textbox)
|
242 |
messages = [
|
243 |
-
{"role": "system", "content":
|
244 |
]
|
245 |
for i in Textbox2_edited:
|
246 |
messages.append(
|
247 |
{"role": "user", "content": i}
|
248 |
)
|
249 |
try:
|
250 |
-
sleep(0.8)
|
251 |
chat = openai.ChatCompletion.create(
|
252 |
model="gpt-3.5-turbo", messages=messages
|
253 |
)
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
messages.append({"role": "assistant", "content": reply})
|
257 |
return reply
|
258 |
-
except
|
259 |
-
print(traceback.format_exc())
|
260 |
return "Please Wait!"
|
261 |
else:
|
262 |
return "Failed"
|
|
|
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 |
+
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
|
95 |
content = os.environ.get("content")
|
96 |
+
content2 = os.environ.get("content2")
|
97 |
link1 = os.environ.get("link1")
|
98 |
path = os.environ.get("path")
|
99 |
link2 = os.environ.get("link2")
|
|
|
145 |
Textbox2_edited = list(Textbox2_edited)
|
146 |
Textbox2_edited.append(Textbox)
|
147 |
messages = [
|
148 |
+
{"role": "system", "content": content2},
|
149 |
]
|
150 |
for i in Textbox2_edited:
|
151 |
messages.append(
|
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 |
+
response = requests.post(target, json={
|
160 |
+
"messages":messages,
|
161 |
+
"model":"gpt-3.5-turbo-003",
|
162 |
+
"max_tokens":"null",
|
163 |
+
"temperature":1,
|
164 |
+
"presence_penalty":0,
|
165 |
+
"top_p":1,
|
166 |
+
"frequency_penalty":0,
|
167 |
+
"stream":False
|
168 |
+
}).json()
|
169 |
+
reply = response['choices'][0]['message']['content']
|
170 |
messages.append({"role": "assistant", "content": reply})
|
171 |
return reply
|
172 |
+
except:
|
|
|
173 |
return "Please Wait!"
|
174 |
else:
|
175 |
return "Failed"
|