Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gradio_client import Client, file
|
| 2 |
+
|
| 3 |
+
client = Client("abidlabs/en2fr")
|
| 4 |
+
inputs = ["Hello", "Bonjour", "Hola", "Guten Tag", "Ciao"]
|
| 5 |
+
|
| 6 |
+
start_total = time.time()
|
| 7 |
+
def fetch_result(i):
|
| 8 |
+
start = time.time()
|
| 9 |
+
job = client.submit(i, api_name="/predict")
|
| 10 |
+
result = job.result()
|
| 11 |
+
end = time.time()
|
| 12 |
+
duration = end - start
|
| 13 |
+
return result, duration
|
| 14 |
+
|
| 15 |
+
def ens2frs(ens):
|
| 16 |
+
en = ens.split("\n")
|
| 17 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 18 |
+
results = list(executor.map(fetch_result, en))
|
| 19 |
+
frs = []
|
| 20 |
+
for result, duration in results:
|
| 21 |
+
print(f"Result:{result}, Time taken: {duration:.2f} seconds")
|
| 22 |
+
frs.append[result, duration]
|
| 23 |
+
|
| 24 |
+
end_total = time.time()
|
| 25 |
+
duration_total = end_total - start_total
|
| 26 |
+
print(f"total time: {duration_total:.2f} seconds")
|
| 27 |
+
return frs
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as app:
|
| 30 |
+
ens = gr.TextArea(
|
| 31 |
+
"""love
|
| 32 |
+
book
|
| 33 |
+
world
|
| 34 |
+
wide""")
|
| 35 |
+
button1 = gr.Button("↓en2fr")
|
| 36 |
+
output = gr.Dataframe(label="result")
|
| 37 |
+
|
| 38 |
+
button1.click(ens2frs, inputs=ens, outputs=output)
|
| 39 |
+
|
| 40 |
+
app.launch(debug=True, share=True)
|