Spaces:
Runtime error
Runtime error
Commit
·
9213df3
1
Parent(s):
62a6cd4
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
from time import time
|
5 |
from html import escape
|
6 |
-
import os
|
7 |
import torch
|
8 |
-
import transformers
|
9 |
from transformers import RobertaModel, AutoTokenizer
|
10 |
|
11 |
-
#@st.cache(show_spinner=False)
|
12 |
-
#def load():
|
13 |
-
# text_encoder = RobertaModel.from_pretrained('SajjadAyoubi/clip-fa-text')
|
14 |
-
# image_embeddings = torch.load('embedding.pt')
|
15 |
-
# links = np.load('data.npy', allow_pickle=True)
|
16 |
-
# return text_encoder, links, image_embeddings
|
17 |
-
|
18 |
|
19 |
tokenizer = AutoTokenizer.from_pretrained('SajjadAyoubi/clip-fa-text')
|
20 |
text_encoder = RobertaModel.from_pretrained('SajjadAyoubi/clip-fa-text').eval()
|
@@ -23,10 +12,10 @@ links = np.load('data.npy', allow_pickle=True)
|
|
23 |
|
24 |
|
25 |
|
26 |
-
def get_html(url_list
|
27 |
html = "<div style='margin-top: 50px; max-width: 1200px; display: flex; flex-wrap: wrap; justify-content: space-evenly'>"
|
28 |
for url in url_list:
|
29 |
-
html2 = f"<img style='height:
|
30 |
html = html + html2
|
31 |
html += "</div>"
|
32 |
return html
|
@@ -50,15 +39,6 @@ def main():
|
|
50 |
.block-container{
|
51 |
max-width: 1200px;
|
52 |
}
|
53 |
-
div.row-widget.stRadio > div{
|
54 |
-
flex-direction:row;
|
55 |
-
display: flex;
|
56 |
-
justify-content: center;
|
57 |
-
}
|
58 |
-
div.row-widget.stRadio > div > label{
|
59 |
-
margin-left: 5px;
|
60 |
-
margin-right: 5px;
|
61 |
-
}
|
62 |
section.main>div:first-child {
|
63 |
padding-top: 0px;
|
64 |
}
|
@@ -76,20 +56,14 @@ def main():
|
|
76 |
}
|
77 |
</style>''',
|
78 |
unsafe_allow_html=True)
|
79 |
-
|
|
|
80 |
_, c, _ = st.columns((1, 3, 1))
|
81 |
query = c.text_input('Search text', value='مرغ دریای')
|
82 |
if len(query) > 0:
|
83 |
results = image_search(query)
|
84 |
-
start = time()
|
85 |
st.markdown(get_html(results), unsafe_allow_html=True)
|
86 |
-
end = time()
|
87 |
-
st.text(str(end - start))
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
print()
|
93 |
|
94 |
if __name__ == '__main__':
|
95 |
main()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import numpy as np
|
|
|
3 |
from html import escape
|
|
|
4 |
import torch
|
|
|
5 |
from transformers import RobertaModel, AutoTokenizer
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
tokenizer = AutoTokenizer.from_pretrained('SajjadAyoubi/clip-fa-text')
|
9 |
text_encoder = RobertaModel.from_pretrained('SajjadAyoubi/clip-fa-text').eval()
|
|
|
12 |
|
13 |
|
14 |
|
15 |
+
def get_html(url_list):
|
16 |
html = "<div style='margin-top: 50px; max-width: 1200px; display: flex; flex-wrap: wrap; justify-content: space-evenly'>"
|
17 |
for url in url_list:
|
18 |
+
html2 = f"<img style='height: 200px; margin: 2px' src='{escape(url)}'>"
|
19 |
html = html + html2
|
20 |
html += "</div>"
|
21 |
return html
|
|
|
39 |
.block-container{
|
40 |
max-width: 1200px;
|
41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
section.main>div:first-child {
|
43 |
padding-top: 0px;
|
44 |
}
|
|
|
56 |
}
|
57 |
</style>''',
|
58 |
unsafe_allow_html=True)
|
59 |
+
|
60 |
+
# st.sidebar.markdown(description)
|
61 |
_, c, _ = st.columns((1, 3, 1))
|
62 |
query = c.text_input('Search text', value='مرغ دریای')
|
63 |
if len(query) > 0:
|
64 |
results = image_search(query)
|
|
|
65 |
st.markdown(get_html(results), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
66 |
|
|
|
67 |
|
68 |
if __name__ == '__main__':
|
69 |
main()
|