tommy24 commited on
Commit
b5c69b7
·
1 Parent(s): 0c164e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -20
app.py CHANGED
@@ -78,6 +78,106 @@
78
 
79
  # iface.launch()
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  from time import sleep
82
  import gradio as gr
83
  import traceback
@@ -87,7 +187,7 @@ import random
87
  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
  content = os.environ.get("content")
@@ -138,29 +238,21 @@ def function(Textbox,Textbox2, Textbox3):
138
  # model = os.environ.get("model")
139
  # hrc = os.environ.get("hrc")
140
  if Textbox3 == target:
141
- Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
142
- Textbox2 = Textbox2.split(",")
143
- Textbox2_edited = [x.strip() for x in Textbox2]
144
- Textbox2_edited = list(Textbox2_edited)
145
- Textbox2_edited.append(Textbox)
146
- messages = [
147
- {"role": "system", "content": content2},
148
- ]
149
- for i in Textbox2_edited:
150
- messages.append(
151
- {"role": "user", "content": i}
152
- )
153
  try:
154
  # sleep(0.8)
155
  # headers = {
156
  # "Authorization": f"Bearer {auth_key}"
157
  # }
158
- response = requests.post(target2, json={
159
- "messages": messages
160
- }).json()
 
 
 
 
 
161
  # reply = response['choices'][0]['message']['content']
162
- reply = response["content"]
163
- messages.append({"role": "assistant", "content": reply})
164
  return reply
165
  except Exception as e:
166
  print(traceback.format_exc())
@@ -170,8 +262,9 @@ def function(Textbox,Textbox2, Textbox3):
170
 
171
  inputs = [
172
  gr.inputs.Textbox(label="Textbox",type="text"),
173
- gr.inputs.Textbox(label="Textbox2",type="text"),
174
- gr.inputs.Textbox(label="Textbox3",type="password")
 
175
  ]
176
 
177
  iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
 
78
 
79
  # iface.launch()
80
 
81
+ # from time import sleep
82
+ # import gradio as gr
83
+ # import traceback
84
+ # import requests
85
+ # import openai
86
+ # import random
87
+ # 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
+ # content = os.environ.get("content")
94
+ # content2 = os.environ.get("content2")
95
+ # auth_key = os.environ.get("auth_key")
96
+ # link1 = os.environ.get("link1")
97
+ # path = os.environ.get("path")
98
+ # link2 = os.environ.get("link2")
99
+ # if "/web" in Textbox.lower() or "web" in Textbox.lower():
100
+ # try:
101
+ # prompt = Textbox.replace("/web","")
102
+ # except:
103
+ # prompt = Textbox.replace("web","")
104
+ # headers = {
105
+ # "authority": link1,
106
+ # "method": "POST",
107
+ # "path": path,
108
+ # "scheme": "https",
109
+ # "accept": "application/json, text/plain, */*",
110
+ # "accept-encoding": "gzip, deflate, br",
111
+ # "accept-language": "en-US,en;q=0.9",
112
+ # "content-length": "88",
113
+ # "content-type": "application/json",
114
+ # "origin": link2,
115
+ # "referer": f"{link2}/",
116
+ # "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
117
+ # "sec-ch-ua-mobile": "?0",
118
+ # "sec-ch-ua-platform": '"Windows"',
119
+ # "sec-fetch-dest": "empty",
120
+ # "sec-fetch-mode": "cors",
121
+ # "sec-fetch-site": "same-site",
122
+ # "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"
123
+ # }
124
+ # href = os.environ.get("href")
125
+ # response = requests.post(href,json={
126
+ # "Body":prompt,
127
+ # "From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
128
+ # },headers=headers)
129
+ # data = response.json()
130
+ # data = data["message"]
131
+ # trigger = os.environ.get("trigger")
132
+ # if trigger in data:
133
+ # data = data.replace(trigger,"John")
134
+ # return data
135
+ # else:
136
+ # return data
137
+ # else:
138
+ # # model = os.environ.get("model")
139
+ # # hrc = os.environ.get("hrc")
140
+ # if Textbox3 == target:
141
+ # Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
142
+ # Textbox2 = Textbox2.split(",")
143
+ # Textbox2_edited = [x.strip() for x in Textbox2]
144
+ # Textbox2_edited = list(Textbox2_edited)
145
+ # Textbox2_edited.append(Textbox)
146
+ # messages = [
147
+ # {"role": "system", "content": content2},
148
+ # ]
149
+ # for i in Textbox2_edited:
150
+ # messages.append(
151
+ # {"role": "user", "content": i}
152
+ # )
153
+ # try:
154
+ # # sleep(0.8)
155
+ # # headers = {
156
+ # # "Authorization": f"Bearer {auth_key}"
157
+ # # }
158
+ # response = requests.post(target2, json={
159
+ # "messages": messages
160
+ # }).json()
161
+ # # reply = response['choices'][0]['message']['content']
162
+ # reply = response["content"]
163
+ # messages.append({"role": "assistant", "content": reply})
164
+ # return reply
165
+ # except Exception as e:
166
+ # print(traceback.format_exc())
167
+ # return "Please Wait!"
168
+ # else:
169
+ # return "Failed"
170
+
171
+ # inputs = [
172
+ # gr.inputs.Textbox(label="Textbox",type="text"),
173
+ # gr.inputs.Textbox(label="Textbox2",type="text"),
174
+ # gr.inputs.Textbox(label="Textbox3",type="password")
175
+ # ]
176
+
177
+ # iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
178
+
179
+ # iface.launch()
180
+
181
  from time import sleep
182
  import gradio as gr
183
  import traceback
 
187
  import base64
188
  import os
189
 
190
+ def function(Textbox,Textbox2, Textbox3, Textbox4):
191
  target = os.environ.get("target")
192
  target2 = os.environ.get("target2")
193
  content = os.environ.get("content")
 
238
  # model = os.environ.get("model")
239
  # hrc = os.environ.get("hrc")
240
  if Textbox3 == target:
 
 
 
 
 
 
 
 
 
 
 
 
241
  try:
242
  # sleep(0.8)
243
  # headers = {
244
  # "Authorization": f"Bearer {auth_key}"
245
  # }
246
+ response = requests.post(target2, headers={
247
+ "Content-Type": "application/json"
248
+ }, data=json.dumps({
249
+ "text": user,
250
+ "key": auth_key,
251
+ "playerId": Textbox4,
252
+ "speak": False
253
+ }))
254
  # reply = response['choices'][0]['message']['content']
255
+ reply = response["output"]["text"]
 
256
  return reply
257
  except Exception as e:
258
  print(traceback.format_exc())
 
262
 
263
  inputs = [
264
  gr.inputs.Textbox(label="Textbox",type="text"),
265
+ # gr.inputs.Textbox(label="Textbox2",type="text"),
266
+ gr.inputs.Textbox(label="Textbox3",type="password"),
267
+ gr.inputs.Textbox(label="Textbox4",type="text")
268
  ]
269
 
270
  iface = gr.Interface(fn=function, inputs=inputs, outputs="text")