File size: 1,281 Bytes
ed18434
11f096b
b04ed84
79eb6b0
11f096b
ed18434
 
 
1cc4be1
ed18434
 
 
 
 
 
 
 
 
1cc4be1
0ea1f1c
ed18434
 
 
 
 
 
9316cdf
0ea1f1c
ed18434
 
 
 
0ea1f1c
 
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
43
44
45
46
47
48
from gradio_client import Client, file
import gradio as gr
import time 
import concurrent

client = Client("abidlabs/en2fr")
inputs = ["Hello", "Bonjour", "Hola", "Guten Tag", "Ciao"]


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):
    start_total = time.time() 
    acum = 0
    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])
        acum += duration

    end_total = time.time()
    duration_total = end_total - start_total
    print(f"total time:  {duration_total:.2f} seconds")
    print(f"acum time:  {acum:.2f} seconds")
    print(f"Efficiency:  {acum/duration_total*100:.1f} %")
    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)