Spaces:
Runtime error
Runtime error
gaspar-avit
commited on
Commit
·
1dcce84
1
Parent(s):
727f9f0
Upload 2 files
Browse files- app.py +7 -33
- requirements.txt +2 -1
app.py
CHANGED
@@ -8,23 +8,21 @@ import numpy as np
|
|
8 |
import json
|
9 |
import requests
|
10 |
import os
|
|
|
11 |
|
12 |
from streamlit import session_state as session
|
13 |
from datetime import time, datetime
|
14 |
from zipfile import ZipFile
|
15 |
-
from sentence_transformers import SentenceTransformer
|
16 |
-
from diffusers import DiffusionPipeline
|
17 |
from htbuilder import HtmlElement, div, ul, li, br, hr, a, p, img, styles, classes, fonts
|
18 |
from htbuilder.units import percent, px
|
19 |
from htbuilder.funcs import rgba, rgb
|
20 |
-
|
21 |
|
22 |
###############################
|
23 |
## --- GLOBAL VARIABLES ---- ##
|
24 |
###############################
|
25 |
|
26 |
|
27 |
-
IS_MODEL_LOADED = False
|
28 |
PATH_JSON = '/home/user/.kaggle/kaggle.json'
|
29 |
|
30 |
|
@@ -123,14 +121,6 @@ def authenticate_kaggle():
|
|
123 |
api = KaggleApi()
|
124 |
api.authenticate()
|
125 |
|
126 |
-
'''
|
127 |
-
try:
|
128 |
-
api.authenticate()
|
129 |
-
except:
|
130 |
-
with open(PATH_JSON, 'w') as file:
|
131 |
-
json.dump(api_token, file)
|
132 |
-
api.authenticate()
|
133 |
-
'''
|
134 |
|
135 |
@st.experimental_memo(persist=True, show_spinner=False, suppress_st_warning=True)
|
136 |
def load_dataset():
|
@@ -166,14 +156,6 @@ def load_dataset():
|
|
166 |
|
167 |
return data
|
168 |
|
169 |
-
@st.cache(persist=True, show_spinner=False, allow_output_mutation=True, suppress_st_warning=True)
|
170 |
-
def load_model():
|
171 |
-
model = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
172 |
-
IS_MODEL_LOADED = True
|
173 |
-
return model
|
174 |
-
#return DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
175 |
-
#return DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-2")
|
176 |
-
|
177 |
|
178 |
def query_summary(text):
|
179 |
"""
|
@@ -226,18 +208,16 @@ def generate_poster(movie_data):
|
|
226 |
|
227 |
|
228 |
# Get image based on synopsis
|
229 |
-
with st.spinner("Generating poster image
|
230 |
poster_image = query_generate(synopsis_sum)
|
231 |
|
232 |
-
|
233 |
-
from PIL import Image
|
234 |
try:
|
235 |
image = Image.open(io.BytesIO(poster_image))
|
236 |
-
st.image(image, caption=movie_data.title.values[0])
|
237 |
-
return image
|
238 |
except:
|
239 |
st.text(poster_image)
|
240 |
-
|
241 |
|
242 |
return image
|
243 |
# ------------------------------------------------------- #
|
@@ -288,11 +268,5 @@ if __name__ == "__main__":
|
|
288 |
|
289 |
|
290 |
if is_clicked:
|
291 |
-
|
292 |
-
|
293 |
-
st.text("")
|
294 |
-
st.text("")
|
295 |
-
st.text("")
|
296 |
|
297 |
-
if image is not None:
|
298 |
-
st.image(image, caption=session.selected_movie.title.values[0])
|
|
|
8 |
import json
|
9 |
import requests
|
10 |
import os
|
11 |
+
import io
|
12 |
|
13 |
from streamlit import session_state as session
|
14 |
from datetime import time, datetime
|
15 |
from zipfile import ZipFile
|
|
|
|
|
16 |
from htbuilder import HtmlElement, div, ul, li, br, hr, a, p, img, styles, classes, fonts
|
17 |
from htbuilder.units import percent, px
|
18 |
from htbuilder.funcs import rgba, rgb
|
19 |
+
from PIL import Image
|
20 |
|
21 |
###############################
|
22 |
## --- GLOBAL VARIABLES ---- ##
|
23 |
###############################
|
24 |
|
25 |
|
|
|
26 |
PATH_JSON = '/home/user/.kaggle/kaggle.json'
|
27 |
|
28 |
|
|
|
121 |
api = KaggleApi()
|
122 |
api.authenticate()
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
@st.experimental_memo(persist=True, show_spinner=False, suppress_st_warning=True)
|
126 |
def load_dataset():
|
|
|
156 |
|
157 |
return data
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
def query_summary(text):
|
161 |
"""
|
|
|
208 |
|
209 |
|
210 |
# Get image based on synopsis
|
211 |
+
with st.spinner("Generating poster image..."):
|
212 |
poster_image = query_generate(synopsis_sum)
|
213 |
|
214 |
+
# Show image
|
|
|
215 |
try:
|
216 |
image = Image.open(io.BytesIO(poster_image))
|
217 |
+
st.image(image, caption="Movie: " + movie_data.title.values[0])
|
|
|
218 |
except:
|
219 |
st.text(poster_image)
|
220 |
+
|
221 |
|
222 |
return image
|
223 |
# ------------------------------------------------------- #
|
|
|
268 |
|
269 |
|
270 |
if is_clicked:
|
271 |
+
generate_poster(data[data.title==session.selected_movie])
|
|
|
|
|
|
|
|
|
272 |
|
|
|
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ zipfile39
|
|
4 |
sentence-transformers
|
5 |
diffusers
|
6 |
accelerate
|
7 |
-
htbuilder
|
|
|
|
4 |
sentence-transformers
|
5 |
diffusers
|
6 |
accelerate
|
7 |
+
htbuilder
|
8 |
+
PIL
|