Spaces:
Runtime error
Runtime error
changed the process image function
Browse files- app.py +9 -4
- sample_input.mp3 +0 -0
- test.py +40 -0
app.py
CHANGED
|
@@ -76,12 +76,17 @@ def convert_image_to_required_format(image):
|
|
| 76 |
"""
|
| 77 |
convert image from numpy to base64
|
| 78 |
"""
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def process_image_with_openai(image):
|
| 84 |
-
|
| 85 |
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 86 |
oai_org = os.getenv('OAI_ORG')
|
| 87 |
if openai_api_key is None:
|
|
@@ -92,7 +97,7 @@ def process_image_with_openai(image):
|
|
| 92 |
"messages": [
|
| 93 |
{
|
| 94 |
"role": "user",
|
| 95 |
-
"content":
|
| 96 |
}
|
| 97 |
],
|
| 98 |
"max_tokens": 300
|
|
|
|
| 76 |
"""
|
| 77 |
convert image from numpy to base64
|
| 78 |
"""
|
| 79 |
+
img = base64.b64encode(image).decode('utf-8')
|
| 80 |
+
image_name = np.random.randint(0, 10)
|
| 81 |
+
with open(f'{image_name}.png', 'wb') as f:
|
| 82 |
+
f.write(base64.b64decode(img))
|
| 83 |
+
return image_name
|
| 84 |
+
|
| 85 |
+
|
| 86 |
|
| 87 |
|
| 88 |
def process_image_with_openai(image):
|
| 89 |
+
image_name = convert_image_to_required_format(image)
|
| 90 |
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 91 |
oai_org = os.getenv('OAI_ORG')
|
| 92 |
if openai_api_key is None:
|
|
|
|
| 97 |
"messages": [
|
| 98 |
{
|
| 99 |
"role": "user",
|
| 100 |
+
"content": image_name
|
| 101 |
}
|
| 102 |
],
|
| 103 |
"max_tokens": 300
|
sample_input.mp3
ADDED
|
Binary file (10.3 kB). View file
|
|
|
test.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio library
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import base64
|
| 5 |
+
import time
|
| 6 |
+
import gradio_client as grc
|
| 7 |
+
# client = grc.InterfaceDescriptionClient("https://gradio.app")
|
| 8 |
+
# define a function that takes input and returns output
|
| 9 |
+
client = grc.Client("facebook/seamless_m4t")
|
| 10 |
+
|
| 11 |
+
print(client.view_api(all_endpoints=True))
|
| 12 |
+
job = client.submit(
|
| 13 |
+
"S2TT",
|
| 14 |
+
"file",
|
| 15 |
+
None,
|
| 16 |
+
"sample_input.mp3",
|
| 17 |
+
"",
|
| 18 |
+
"French",
|
| 19 |
+
"English",
|
| 20 |
+
api_name="/run",
|
| 21 |
+
)
|
| 22 |
+
while job.done() == False :
|
| 23 |
+
time.sleep(1)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
gr.Markdown(job.result())
|
| 27 |
+
# return out
|
| 28 |
+
|
| 29 |
+
# # print(client.view_api(all_endpoints=True))
|
| 30 |
+
# def convert_image_to_required_format(audio):
|
| 31 |
+
# sr, data = audio
|
| 32 |
+
# return str(type(sr))+str(type(data))
|
| 33 |
+
|
| 34 |
+
# # create a gradio interface
|
| 35 |
+
# iface = gr.Interface(
|
| 36 |
+
# fn=sound_to_text,
|
| 37 |
+
# inputs=[gr.Audio()],
|
| 38 |
+
# outputs=[gr.Markdown(label="Output Text")],
|
| 39 |
+
# )
|
| 40 |
+
# iface.launch()
|