Fix async
Browse files
app.py
CHANGED
@@ -7,13 +7,8 @@ executor = ThreadPoolExecutor()
|
|
7 |
|
8 |
model_pipeline = pipeline("text2text-generation", model="tribler/dsi-search-on-toy-dataset")
|
9 |
|
10 |
-
async def
|
11 |
-
|
12 |
-
results = await loop.run_in_executor(executor, model_pipeline, query, {"max_length": 60})
|
13 |
-
return results
|
14 |
-
|
15 |
-
async def process_query(query):
|
16 |
-
results = await async_model_pipeline(query)
|
17 |
result_text = results[0]['generated_text'].strip()
|
18 |
if result_text.startswith("http"):
|
19 |
youtube_id = result_text.split('watch?v=')[-1]
|
@@ -25,6 +20,13 @@ async def process_query(query):
|
|
25 |
bitcoin_logo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/800px-Bitcoin.svg.png"
|
26 |
return gr.Textbox(f'<div style="display:flex;align-items:center;"><img src="{bitcoin_logo_url}" alt="Bitcoin Logo" style="width:20px;height:20px;margin-right:5px;"><span>{result_text}</span></div>')
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
interface = gr.Interface(fn=process_query,
|
29 |
inputs=gr.Textbox(label="Query"),
|
30 |
outputs="html",
|
|
|
7 |
|
8 |
model_pipeline = pipeline("text2text-generation", model="tribler/dsi-search-on-toy-dataset")
|
9 |
|
10 |
+
async def async_process_query(query):
|
11 |
+
results = model_pipeline(query)
|
|
|
|
|
|
|
|
|
|
|
12 |
result_text = results[0]['generated_text'].strip()
|
13 |
if result_text.startswith("http"):
|
14 |
youtube_id = result_text.split('watch?v=')[-1]
|
|
|
20 |
bitcoin_logo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/800px-Bitcoin.svg.png"
|
21 |
return gr.Textbox(f'<div style="display:flex;align-items:center;"><img src="{bitcoin_logo_url}" alt="Bitcoin Logo" style="width:20px;height:20px;margin-right:5px;"><span>{result_text}</span></div>')
|
22 |
|
23 |
+
|
24 |
+
async def process_query(query):
|
25 |
+
try:
|
26 |
+
return await asyncio.wait_for(async_process_query(query), timeout=10)
|
27 |
+
except asyncio.TimeoutError:
|
28 |
+
return "Processing timed out."
|
29 |
+
|
30 |
interface = gr.Interface(fn=process_query,
|
31 |
inputs=gr.Textbox(label="Query"),
|
32 |
outputs="html",
|