Spaces:
Runtime error
Runtime error
code update
Browse files- app.py +32 -0
- flagged/log.csv +7 -0
- teste1.py +11 -0
app.py
CHANGED
@@ -22,7 +22,13 @@ You can use this model to generate audio from text in multiple languages.
|
|
22 |
It can be used as an API or as a standalone application.
|
23 |
"""
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
def predict(text, lang, audio, request: gr.Request):
|
|
|
26 |
output_text = {"verdict ": "SUCCESS"} # Initialize as a dictionary
|
27 |
output_text["Text"] = text
|
28 |
output_text["Language"] = lang
|
@@ -31,6 +37,32 @@ def predict(text, lang, audio, request: gr.Request):
|
|
31 |
# Convert headers to a dictionary and include them in the output_text
|
32 |
output_text["headers"] = dict(request.headers.items())
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
output_text_json = json.dumps(output_text)
|
35 |
return output_text_json
|
36 |
|
|
|
22 |
It can be used as an API or as a standalone application.
|
23 |
"""
|
24 |
|
25 |
+
MIN_TEXT_LENGTH = 5
|
26 |
+
MAX_TEXT_LENGTH = 10000
|
27 |
+
SUPPORTED_LANGS_BY_APP = ["en", "es", "fr", "it", "pt", "nl"]
|
28 |
+
SUPPORTED_LANGS_BY_MODEL = ["en", "es", "fr", "it", "pt", "nl"]
|
29 |
+
|
30 |
def predict(text, lang, audio, request: gr.Request):
|
31 |
+
|
32 |
output_text = {"verdict ": "SUCCESS"} # Initialize as a dictionary
|
33 |
output_text["Text"] = text
|
34 |
output_text["Language"] = lang
|
|
|
37 |
# Convert headers to a dictionary and include them in the output_text
|
38 |
output_text["headers"] = dict(request.headers.items())
|
39 |
|
40 |
+
if not request:
|
41 |
+
gr.Warning("No request")
|
42 |
+
return None
|
43 |
+
if len(text) < MIN_TEXT_LENGTH:
|
44 |
+
gr.Warning("Text to short. Please provide a longer text, min " + str(MIN_TEXT_LENGTH)+" characters")
|
45 |
+
return None
|
46 |
+
if len(text) > MAX_TEXT_LENGTH:
|
47 |
+
gr.Warning("Text to long. Please provide a shorter text, max " + str(MAX_TEXT_LENGTH)+" characters")
|
48 |
+
return None
|
49 |
+
if lang not in SUPPORTED_LANGS_BY_MODEL:
|
50 |
+
gr.Warning("Language not supported by the model. Please select a supported language")
|
51 |
+
return None
|
52 |
+
else:
|
53 |
+
if lang not in SUPPORTED_LANGS_BY_APP:
|
54 |
+
gr.Warning("Language not supported for now. Please select a supported language")
|
55 |
+
return None
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
#if not audio:
|
60 |
+
# gr.Warning("Please provide an audio file")
|
61 |
+
# return None
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
output_text_json = json.dumps(output_text)
|
67 |
return output_text_json
|
68 |
|
flagged/log.csv
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Text Prompt,Language,audio,output,flag,username,timestamp
|
2 |
+
"'
|
3 |
+
Não sou nada,
|
4 |
+
não serei nada,
|
5 |
+
não posso querer ser nada.
|
6 |
+
À parte isso, tenho em mim todos os sonhos do mundo.
|
7 |
+
",pt,,"{""verdict "": ""SUCCESS"", ""Text"": ""\nN\u00e3o sou nada,\nn\u00e3o serei nada,\nn\u00e3o posso querer ser nada.\n\u00c0 parte isso, tenho em mim todos os sonhos do mundo.\n"", ""Language"": ""pt"", ""headers"": {""host"": ""127.0.0.1:7860"", ""connection"": ""keep-alive"", ""content-length"": ""219"", ""sec-ch-ua"": ""\""Chromium\"";v=\""122\"", \""Not(A:Brand\"";v=\""24\"", \""Brave\"";v=\""122\"""", ""sec-ch-ua-platform"": ""\""Windows\"""", ""sec-ch-ua-mobile"": ""?0"", ""user-agent"": ""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"", ""content-type"": ""application/json"", ""accept"": ""*/*"", ""sec-gpc"": ""1"", ""origin"": ""http://127.0.0.1:7860"", ""sec-fetch-site"": ""same-origin"", ""sec-fetch-mode"": ""cors"", ""sec-fetch-dest"": ""empty"", ""referer"": ""http://127.0.0.1:7860/"", ""accept-encoding"": ""gzip, deflate, br"", ""accept-language"": ""pt-PT,pt;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6"", ""cookie"": ""_ga=GA1.1.746017540.1710886117; _gid=GA1.1.2086359869.1710886117; _gat_gtag_UA_156449732_1=1; _ga_R1FN4KJKJH=GS1.1.1710911212.6.1.1710912032.0.0.0""}}",,,2024-03-20 05:20:39.707599
|
teste1.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client, file
|
2 |
+
import json
|
3 |
+
|
4 |
+
client = Client("http://127.0.0.1:7860/")
|
5 |
+
result = client.predict(
|
6 |
+
"Hello!!", # str in 'Text Prompt' Textbox component
|
7 |
+
"en", # Literal['en', 'es', 'fr', 'it', 'pt', 'nl'] in 'Language' Dropdown component
|
8 |
+
file('https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'), # filepath in 'audio' Audio component
|
9 |
+
api_name="/predict"
|
10 |
+
)
|
11 |
+
print(result)
|