mg98 commited on
Commit
2ea0187
·
verified ·
1 Parent(s): 3c91726

Deploy app

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ model_pipeline = pipeline("text2text-generation", model="tribler/dsi-search-on-toy-dataset")
5
+
6
+ def process_query(query):
7
+ results = model_pipeline(query, max_length=60)
8
+ result_text = results[0]['generated_text'].strip()
9
+ print(result_text)
10
+ if result_text.startswith("http"):
11
+ youtube_id = result_text.split('watch?v=')[-1]
12
+ iframe = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{youtube_id}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
13
+ return gr.HTML(iframe)
14
+ elif result_text.startswith("magnet"):
15
+ return gr.HTML(f'<a href="{result_text}" target="_blank">{result_text}</a>')
16
+ else:
17
+ bitcoin_logo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/800px-Bitcoin.svg.png"
18
+ 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>')
19
+
20
+ interface = gr.Interface(fn=process_query,
21
+ inputs=gr.Textbox(label="Query"),
22
+ outputs="html",
23
+ title="Search Interface",
24
+ description="Search for movie trailers, music torrents, and bitcoin wallet addresses.",
25
+ article="This interface searches a toy dataset and returns a YouTube URL, magnet link, or Bitcoin wallet address.",
26
+ examples=[["spider man"], ["oceans 13"], ["sister starlight"], ["bitcoin address of xileno"]])
27
+
28
+ if __name__ == "__main__":
29
+ interface.launch()
30
+