Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -82,39 +82,62 @@ from time import sleep
|
|
82 |
import gradio as gr
|
83 |
import requests
|
84 |
import openai
|
|
|
|
|
85 |
import os
|
86 |
|
87 |
def function(Textbox,Textbox2,Textbox3):
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
content = os.environ.get("content")
|
92 |
-
# model = os.environ.get("model")
|
93 |
-
# hrc = os.environ.get("hrc")
|
94 |
-
if Textbox3 == target:
|
95 |
-
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
96 |
-
Textbox2 = Textbox2.split(",")
|
97 |
-
Textbox2_edited = [x.strip() for x in Textbox2]
|
98 |
-
Textbox2_edited = list(Textbox2_edited)
|
99 |
-
Textbox2_edited.append(Textbox)
|
100 |
-
messages = [
|
101 |
-
{"role": "system", "content": content},
|
102 |
-
]
|
103 |
-
for i in Textbox2_edited:
|
104 |
-
messages.append(
|
105 |
-
{"role": "user", "content": i}
|
106 |
-
)
|
107 |
-
try:
|
108 |
-
sleep(0.8)
|
109 |
-
chat = openai.ChatCompletion.create(
|
110 |
-
model="gpt-3.5-turbo", messages=messages
|
111 |
-
)
|
112 |
-
print(messages)
|
113 |
-
reply = chat.choices[0].message.content
|
114 |
-
messages.append({"role": "assistant", "content": reply})
|
115 |
-
return reply
|
116 |
except:
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
else:
|
119 |
return "Failed"
|
120 |
|
|
|
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 |
+
if "/web" in Textbox.lower() or "web" in Textbox.lower():
|
91 |
+
try:
|
92 |
+
prompt = Textbox.replace("/web","")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
except:
|
94 |
+
prompt = Textbox.replace("web","")
|
95 |
+
payload = {
|
96 |
+
"Body":prompt,
|
97 |
+
"From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}"
|
98 |
+
}
|
99 |
+
href = os.environ.get("href")
|
100 |
+
response = requests.post(href,data=payload)
|
101 |
+
|
102 |
+
data = response.json()
|
103 |
+
data = data["message"]
|
104 |
+
if "Lexii" in data:
|
105 |
+
trigger = os.environ.get("trigger")
|
106 |
+
data = data.replace(trigger,"John")
|
107 |
+
return data
|
108 |
+
else:
|
109 |
+
return data
|
110 |
+
else:
|
111 |
+
target = os.environ.get("target")
|
112 |
+
target2 = os.environ.get("target2")
|
113 |
+
openai.api_key = target2
|
114 |
+
content = os.environ.get("content")
|
115 |
+
# model = os.environ.get("model")
|
116 |
+
# hrc = os.environ.get("hrc")
|
117 |
+
if Textbox3 == target:
|
118 |
+
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
119 |
+
Textbox2 = Textbox2.split(",")
|
120 |
+
Textbox2_edited = [x.strip() for x in Textbox2]
|
121 |
+
Textbox2_edited = list(Textbox2_edited)
|
122 |
+
Textbox2_edited.append(Textbox)
|
123 |
+
messages = [
|
124 |
+
{"role": "system", "content": content},
|
125 |
+
]
|
126 |
+
for i in Textbox2_edited:
|
127 |
+
messages.append(
|
128 |
+
{"role": "user", "content": i}
|
129 |
+
)
|
130 |
+
try:
|
131 |
+
sleep(0.8)
|
132 |
+
chat = openai.ChatCompletion.create(
|
133 |
+
model="gpt-3.5-turbo", messages=messages
|
134 |
+
)
|
135 |
+
print(messages)
|
136 |
+
reply = chat.choices[0].message.content
|
137 |
+
messages.append({"role": "assistant", "content": reply})
|
138 |
+
return reply
|
139 |
+
except:
|
140 |
+
return "Please Wait!"
|
141 |
else:
|
142 |
return "Failed"
|
143 |
|