Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
client = Client("Renecto/parallel_en2fr")
|
5 |
+
|
6 |
+
def fetch_result(ens):
|
7 |
+
result = client.predict(
|
8 |
+
ens=ens
|
9 |
+
api_name="/ens2frs"
|
10 |
+
)
|
11 |
+
return result
|
12 |
+
|
13 |
+
def ens2frs(ens1, ens2, ens3):
|
14 |
+
tasks = [ens1, ens2, ens3]
|
15 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
16 |
+
results = list(executor.map(fetch_result, tasks))
|
17 |
+
frs = []
|
18 |
+
for result, duration in results:
|
19 |
+
print(f"Result:{result}, Time taken: {duration:.2f} seconds")
|
20 |
+
frs.extend([result, duration])
|
21 |
+
acum += duration
|
22 |
+
|
23 |
+
end_total = time.time()
|
24 |
+
duration_total = end_total - start_total
|
25 |
+
print(f"total time: {duration_total:.2f} seconds")
|
26 |
+
print(f"acum time: {acum:.2f} seconds")
|
27 |
+
print(f"Efficiency: {acum/duration_total*100:.1f} %")
|
28 |
+
return frs
|
29 |
+
|
30 |
+
|
31 |
+
with gr.Blocks() as app:
|
32 |
+
ens1 = gr.TextArea(
|
33 |
+
"""love
|
34 |
+
book
|
35 |
+
world
|
36 |
+
wide""")
|
37 |
+
ens2 = gr.TextArea(
|
38 |
+
"""hate
|
39 |
+
television
|
40 |
+
local
|
41 |
+
narrow""")
|
42 |
+
ens3 = gr.TextArea(
|
43 |
+
"""neutral
|
44 |
+
radio
|
45 |
+
urban
|
46 |
+
normal""")
|
47 |
+
button1 = gr.Button("↓en2fr")
|
48 |
+
output = gr.Dataframe(label="result")
|
49 |
+
|
50 |
+
button1.click(ens2frs, inputs=ens, outputs=output)
|
51 |
+
|
52 |
+
app.launch(debug=True, share=True)
|