Omnibus commited on
Commit
845d3ac
1 Parent(s): 7e33ee0

Update player.py

Browse files
Files changed (1) hide show
  1. player.py +4 -54
player.py CHANGED
@@ -99,7 +99,7 @@ def build_space(index_sel, vid_file, t_name=None, token=None):
99
  print(vid_slug)
100
  #json_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/{vid_slug}.json'
101
  video_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/resolve/main/videos/{vid_slug}.mp4'
102
- #thumb_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/{vid_slug}.webp'
103
 
104
  r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/raw/main/videos/{vid_slug}.json')
105
  json_out=r.json()
@@ -142,61 +142,11 @@ def build_space(index_sel, vid_file, t_name=None, token=None):
142
  )
143
  except Exception as e:
144
  return gr.HTML(f"""{str(e)}""")
145
-
146
- if t_image != None:
147
-
148
- urllib.request.urlretrieve(f'{t_image}',"gfg.png")
149
- img1 = Image.open("gfg.png")
150
- img1.save(f'img-{uid}.png')
151
-
152
- #img1 = Image.open(t_image)
153
- img1.thumbnail((500,500), Image.Resampling.LANCZOS)
154
- img1.save(f'img2-{uid}.png')
155
-
156
- #output_pro=cv2.imread(f'tmpim-{uid}.png')
157
- #output_pro2=cv2.imread(f'tmpim2-{uid}.png')
158
-
159
- #cv2.imwrite(f"./img-{uid}.png",output_pro)
160
- #cv2.imwrite(f"./img2-{uid}.png",output_pro2)
161
- try:
162
- api.upload_file(
163
- path_or_fileobj=f"./img-{uid}.png",
164
- path_in_repo="card_im.png",
165
- repo_id=repo_name,
166
- token=token,
167
- repo_type="space",
168
- )
169
- t_image = f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/card_im.png"
170
- os.remove(f"./img-{uid}.png")
171
-
172
- print(f"Image Uploaded to: {t_image}")
173
- except Exception as e:
174
- return gr.HTML(f"""{str(e)}""")
175
- try:
176
- api.upload_file(
177
- path_or_fileobj=f"./img2-{uid}.png",
178
- path_in_repo="card_im_crop.png",
179
- repo_id=repo_name,
180
- token=token,
181
- repo_type="space",
182
- )
183
- t_image2 = f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/card_im_crop.png"
184
- os.remove(f"./img2-{uid}.png")
185
-
186
- print(f"Image Uploaded to: {t_image2}")
187
- except Exception as e:
188
- return gr.HTML(f"""{str(e)}""")
189
-
190
- pass
191
- else:
192
- print("Default Image")
193
- t_image="https://huggingface.co/spaces/portal/bin/resolve/main/ai_demo_card.png"
194
- pass
195
-
196
  try:
197
  api_url = f'https://huggingface.co/api/spaces/{model_id}'
198
  #t_iframe = t_space
199
- t_link = f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/ai.html"
200
 
201
  ########## norm
202
  with open("template_front.html", "r") as f:
@@ -204,7 +154,7 @@ def build_space(index_sel, vid_file, t_name=None, token=None):
204
  app = app.replace("$space", video_in)
205
  app = app.replace("$title", t_title)
206
  app = app.replace("$description", t_description)
207
- app = app.replace("$image", t_image)
208
  app = app.replace("$redirect", t_redirect)
209
 
210
  with open("ai.html", "w") as f:
 
99
  print(vid_slug)
100
  #json_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/{vid_slug}.json'
101
  video_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/resolve/main/videos/{vid_slug}.mp4'
102
+ thumb_in = f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/{vid_slug}.webp'
103
 
104
  r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/raw/main/videos/{vid_slug}.json')
105
  json_out=r.json()
 
142
  )
143
  except Exception as e:
144
  return gr.HTML(f"""{str(e)}""")
145
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  try:
147
  api_url = f'https://huggingface.co/api/spaces/{model_id}'
148
  #t_iframe = t_space
149
+ t_link = f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/{f_name}.html"
150
 
151
  ########## norm
152
  with open("template_front.html", "r") as f:
 
154
  app = app.replace("$space", video_in)
155
  app = app.replace("$title", t_title)
156
  app = app.replace("$description", t_description)
157
+ app = app.replace("$image", thumb_in)
158
  app = app.replace("$redirect", t_redirect)
159
 
160
  with open("ai.html", "w") as f: