Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -83,6 +83,7 @@ from io import BytesIO
|
|
83 |
from PIL import Image
|
84 |
import gradio as gr
|
85 |
import numpy as np
|
|
|
86 |
import traceback
|
87 |
import requests
|
88 |
import openai
|
@@ -91,9 +92,10 @@ import base64
|
|
91 |
import os
|
92 |
import urllib.request
|
93 |
|
94 |
-
def function(Textbox, Textbox2, Textbox3):
|
95 |
target = os.environ.get("target")
|
96 |
target2 = os.environ.get("target2")
|
|
|
97 |
# openai.api_key = target2
|
98 |
# openai.api_base = os.environ.get("base")
|
99 |
content = os.environ.get("content")
|
@@ -152,41 +154,81 @@ def function(Textbox, Textbox2, Textbox3):
|
|
152 |
print('IO Error:', str(e))
|
153 |
|
154 |
if Textbox3 == target:
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
else:
|
184 |
return "Failed"
|
185 |
|
186 |
inputs = [
|
187 |
gr.inputs.Textbox(label="Textbox", type="text"),
|
188 |
gr.inputs.Textbox(label="Textbox2", type="text"),
|
189 |
-
gr.inputs.Textbox(label="Textbox3", type="password")
|
|
|
|
|
190 |
]
|
191 |
|
192 |
# outputs = gr.outputs.Image(type="numpy")
|
|
|
83 |
from PIL import Image
|
84 |
import gradio as gr
|
85 |
import numpy as np
|
86 |
+
import replicate
|
87 |
import traceback
|
88 |
import requests
|
89 |
import openai
|
|
|
92 |
import os
|
93 |
import urllib.request
|
94 |
|
95 |
+
def function(Textbox, Textbox2, Textbox3, Dropdown):
|
96 |
target = os.environ.get("target")
|
97 |
target2 = os.environ.get("target2")
|
98 |
+
os.environ["REPLICATE_API_TOKEN"] = os.environ.get("tk")
|
99 |
# openai.api_key = target2
|
100 |
# openai.api_base = os.environ.get("base")
|
101 |
content = os.environ.get("content")
|
|
|
154 |
print('IO Error:', str(e))
|
155 |
|
156 |
if Textbox3 == target:
|
157 |
+
if Dropdown == "Option1":
|
158 |
+
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
159 |
+
Textbox2 = Textbox2.split(",")
|
160 |
+
Textbox2_edited = [x.strip() for x in Textbox2]
|
161 |
+
Textbox2_edited = list(Textbox2_edited)
|
162 |
+
Textbox2_edited.append(Textbox)
|
163 |
+
data = {
|
164 |
+
"messages": [
|
165 |
+
{"role": "system", "content": content}
|
166 |
+
]
|
167 |
+
}
|
168 |
+
for i in Textbox2_edited:
|
169 |
+
data["messages"].append(
|
170 |
+
{"role": "user", "content": i}
|
171 |
+
)
|
172 |
+
try:
|
173 |
+
sleep(0.8)
|
174 |
+
# chat = openai.ChatCompletion.create(
|
175 |
+
# model="gpt-3.5-turbo", messages=messages
|
176 |
+
# )
|
177 |
+
response = requests.post(target2, json=data)
|
178 |
+
reply = response.content.decode("utf-8")
|
179 |
+
# reply = reply.replace(" ", "%20")
|
180 |
+
# image_array = download_image(f"https://api.placid.app/u/pydav4ibo?quote[text]={reply}")
|
181 |
+
data["messages"].append({"role": "assistant", "content": reply})
|
182 |
+
return reply
|
183 |
+
except Exception as e:
|
184 |
+
print(traceback.format_exc())
|
185 |
+
return "Please Wait!"
|
186 |
+
elif Dropdown == "Option2":
|
187 |
+
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
|
188 |
+
Textbox2 = Textbox2.split(",")
|
189 |
+
Textbox2_edited = [x.strip() for x in Textbox2]
|
190 |
+
Textbox2_edited = list(Textbox2_edited)
|
191 |
+
Textbox2_edited.append(Textbox)
|
192 |
+
data = {
|
193 |
+
"messages": [
|
194 |
+
{"role": "system", "content": content}
|
195 |
+
]
|
196 |
+
}
|
197 |
+
for i in Textbox2_edited:
|
198 |
+
data["messages"].append(
|
199 |
+
{"role": "user", "content": i}
|
200 |
+
)
|
201 |
+
try:
|
202 |
+
sleep(0.8)
|
203 |
+
# chat = openai.ChatCompletion.create(
|
204 |
+
# model="gpt-3.5-turbo", messages=messages
|
205 |
+
# )
|
206 |
+
response = requests.post(target2, json=data)
|
207 |
+
reply = response.content.decode("utf-8")
|
208 |
+
# reply = reply.replace(" ", "%20")
|
209 |
+
# image_array = download_image(f"https://api.placid.app/u/pydav4ibo?quote[text]={reply}")
|
210 |
+
data["messages"].append({"role": "assistant", "content": reply})
|
211 |
+
output = replicate.run(
|
212 |
+
"suno-ai/bark:b76242b40d67c76ab6742e987628a2a9ac019e11d56ab96c4e91ce03b79b2787",
|
213 |
+
input={
|
214 |
+
"prompt": reply,
|
215 |
+
"history_prompt": "en_speaker_5"
|
216 |
+
}
|
217 |
+
)
|
218 |
+
output = output["audio_out"]
|
219 |
+
return output
|
220 |
+
except Exception as e:
|
221 |
+
print(traceback.format_exc())
|
222 |
+
return "Please Wait!"
|
223 |
else:
|
224 |
return "Failed"
|
225 |
|
226 |
inputs = [
|
227 |
gr.inputs.Textbox(label="Textbox", type="text"),
|
228 |
gr.inputs.Textbox(label="Textbox2", type="text"),
|
229 |
+
gr.inputs.Textbox(label="Textbox3", type="password"),
|
230 |
+
gr.inputs.Dropdown(["Option1", "Option2"], label="Dropdown")
|
231 |
+
|
232 |
]
|
233 |
|
234 |
# outputs = gr.outputs.Image(type="numpy")
|