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