Spaces:
Sleeping
Sleeping
Duplicate from Omnibus/Spaces-on-Twitter
Browse filesCo-authored-by: Bot <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +193 -0
- requirements.txt +1 -0
- sauce.css +84 -0
- template/Default-AI.png +0 -0
- template/ai.html +19 -0
- template/ai_demo_card.png +0 -0
- template/back.html +33 -0
- template/front.html +13 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Interactive Spaces on Twitter
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
duplicated_from: Omnibus/Spaces-on-Twitter
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import cv2
|
4 |
+
import uuid
|
5 |
+
from PIL import Image
|
6 |
+
import gradio as gr
|
7 |
+
from pathlib import Path
|
8 |
+
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
9 |
+
|
10 |
+
token_self = os.environ['HF_TOKEN']
|
11 |
+
|
12 |
+
|
13 |
+
def build_space(t_name,t_space,t_title,t_description,t_redirect,t_image=None,t_image_url=None,token=None):
|
14 |
+
uid = uuid.uuid4()
|
15 |
+
model_id=t_name
|
16 |
+
#model_id="omnibus/fff"
|
17 |
+
if token==None or token=="":
|
18 |
+
token = token_self
|
19 |
+
else:
|
20 |
+
token = token
|
21 |
+
pass
|
22 |
+
api = HfApi(token=token)
|
23 |
+
repo_name = get_full_repo_name(model_id=model_id, token=token)
|
24 |
+
|
25 |
+
if t_redirect==None or t_redirect=="":
|
26 |
+
t_redirect=t_space
|
27 |
+
else:
|
28 |
+
t_redirect=t_redirect
|
29 |
+
pass
|
30 |
+
|
31 |
+
try:
|
32 |
+
print(t_space.rsplit('.hf', 1)[-1])
|
33 |
+
if t_space.rsplit('.hf', 1)[-1] == ".space":
|
34 |
+
repo_url = api.create_repo(
|
35 |
+
repo_id=model_id,
|
36 |
+
repo_type="space",
|
37 |
+
space_sdk="static",
|
38 |
+
private=False,
|
39 |
+
)
|
40 |
+
print(f"""Space Built at {repo_name}""")
|
41 |
+
else:
|
42 |
+
model_id=None
|
43 |
+
repo_name=None
|
44 |
+
t_space=None
|
45 |
+
t_image=None
|
46 |
+
t_image_url=None
|
47 |
+
api=None
|
48 |
+
pass
|
49 |
+
return gr.HTML.update(f"""Invalid Direct URL: must be a Huggingface Space<br>Be sure URL is in lowercase""")
|
50 |
+
except Exception as e:
|
51 |
+
return gr.HTML.update(f"""{str(e)}""")
|
52 |
+
|
53 |
+
if t_image_url != None and t_image_url != "" and t_image==None:
|
54 |
+
t_image=t_image_url
|
55 |
+
print(f"Using image URL {t_image}")
|
56 |
+
pass
|
57 |
+
elif t_image != None:
|
58 |
+
img1 = Image.open(t_image)
|
59 |
+
img1.thumbnail((500,500), Image.Resampling.LANCZOS)
|
60 |
+
img1.save(f'tmpim-{uid}.png')
|
61 |
+
output_pro=cv2.imread(f'tmpim-{uid}.png')
|
62 |
+
|
63 |
+
cv2.imwrite(f"./img-{uid}.png",output_pro)
|
64 |
+
try:
|
65 |
+
api.upload_file(
|
66 |
+
path_or_fileobj=f"./img-{uid}.png",
|
67 |
+
path_in_repo="card_im.png",
|
68 |
+
repo_id=repo_name,
|
69 |
+
token=token,
|
70 |
+
repo_type="space",
|
71 |
+
)
|
72 |
+
t_image = f"https://{repo_name.replace('/','-').replace('_','-')}.hf.space/card_im.png"
|
73 |
+
os.remove(f"./img-{uid}.png")
|
74 |
+
|
75 |
+
print(f"Image Uploaded to: {t_image}")
|
76 |
+
except Exception as e:
|
77 |
+
return gr.HTML.update(f"""{str(e)}""")
|
78 |
+
pass
|
79 |
+
else:
|
80 |
+
print("Default Image")
|
81 |
+
t_image="https://huggingface.co/spaces/portal/bin/resolve/main/ai_demo_card.png"
|
82 |
+
pass
|
83 |
+
|
84 |
+
try:
|
85 |
+
api_url = f'https://huggingface.co/api/spaces/{model_id}'
|
86 |
+
t_iframe = t_space
|
87 |
+
t_link = f"https://{repo_name.replace('/','-').replace('_','-')}.hf.space/ai.html"
|
88 |
+
t_space = f"https://{repo_name.replace('/','-').replace('_','-')}.hf.space/back.html"
|
89 |
+
|
90 |
+
with open("template/ai.html", "r") as f:
|
91 |
+
app = f.read()
|
92 |
+
app = app.replace("$space", t_space)
|
93 |
+
app = app.replace("$title", t_title)
|
94 |
+
app = app.replace("$description", t_description)
|
95 |
+
app = app.replace("$image", t_image)
|
96 |
+
app = app.replace("$redirect", t_redirect)
|
97 |
+
|
98 |
+
with open("ai.html", "w") as f:
|
99 |
+
f.write(app)
|
100 |
+
|
101 |
+
api.upload_file(
|
102 |
+
path_or_fileobj="ai.html",
|
103 |
+
path_in_repo="ai.html",
|
104 |
+
repo_id=repo_name,
|
105 |
+
token=token,
|
106 |
+
repo_type="space",
|
107 |
+
)
|
108 |
+
os.remove("ai.html")
|
109 |
+
|
110 |
+
with open("template/front.html", "r") as f:
|
111 |
+
app = f.read()
|
112 |
+
app = app.replace("$iframe", t_iframe)
|
113 |
+
|
114 |
+
with open("front.html", "w") as f:
|
115 |
+
f.write(app)
|
116 |
+
|
117 |
+
api.upload_file(
|
118 |
+
path_or_fileobj="front.html",
|
119 |
+
path_in_repo="index.html",
|
120 |
+
repo_id=repo_name,
|
121 |
+
token=token,
|
122 |
+
repo_type="space",
|
123 |
+
)
|
124 |
+
os.remove("front.html")
|
125 |
+
|
126 |
+
|
127 |
+
with open("template/back.html", "r") as f:
|
128 |
+
app = f.read()
|
129 |
+
app = app.replace("$iframe", t_iframe)
|
130 |
+
# 3. save the new app.py file
|
131 |
+
with open("back.html", "w") as f:
|
132 |
+
f.write(app)
|
133 |
+
|
134 |
+
api.upload_file(
|
135 |
+
path_or_fileobj="back.html",
|
136 |
+
path_in_repo="back.html",
|
137 |
+
repo_id=repo_name,
|
138 |
+
token=token,
|
139 |
+
repo_type="space",
|
140 |
+
)
|
141 |
+
os.remove("back.html")
|
142 |
+
return gr.HTML.update(f'''<center>Your Interactive Twitter Card Embed Link is:<br><a href="{t_link}" target="_blank">{t_link}</a><center><br>''')
|
143 |
+
except Exception as e:
|
144 |
+
return gr.HTML.update(f"""{str(e)}""")
|
145 |
+
def d_im():
|
146 |
+
output="https://huggingface.co/spaces/portal/bin/resolve/main/ai_demo_card.png"
|
147 |
+
return output
|
148 |
+
|
149 |
+
with gr.Blocks() as build_app:
|
150 |
+
gr.Markdown("""<center><h1>Interactive Twitter Card Builder</h1></center>""")
|
151 |
+
|
152 |
+
with gr.Row():
|
153 |
+
gr.Column(scale=1)
|
154 |
+
with gr.Column(scale=3):
|
155 |
+
with gr.Accordion("Details",open=False):
|
156 |
+
with gr.Tab("Description"):
|
157 |
+
gr.Markdown("""<h7>This space will build an Interactive Twitter Card<br>
|
158 |
+
where Twitter (and other) users can run your Gradio demo<br>
|
159 |
+
right on their Social Media feed.<br><br>
|
160 |
+
*Only works through browser, not Twitter App<br><br>
|
161 |
+
Enter the required information and paste the link that is returned<br>
|
162 |
+
as the only link, along with your message and tags, in your Tweet.<br>
|
163 |
+
When posted, the Interactive Twitter Card should have a Play button<br>
|
164 |
+
which will display the Space you provided.<br><br>
|
165 |
+
Twitter will remember this card associated with the link you post,<br>
|
166 |
+
so any changes will often require a differently named link.<br><br>
|
167 |
+
You can test your link first by omitting your Write token<br>
|
168 |
+
which will assign the default REPO: "portal"<br>(Link: portal-NAME.hf.space)<br><br>
|
169 |
+
This Space is a Demo, and is a Work in Progress<br>
|
170 |
+
No Warranties, Guarantees, or Permissions implied
|
171 |
+
""")
|
172 |
+
with gr.Tab("Credits"):
|
173 |
+
gr.Markdown("""<h7><a href='https://huggingface.co/spaces/anzorq/sd-space-creator'>anzorq/sd-space-creator</a><br>""")
|
174 |
+
|
175 |
+
|
176 |
+
with gr.Box():
|
177 |
+
option_token = gr.Textbox(label="HF Write Token to write to your REPO", placeholder="Optional")
|
178 |
+
t_name = gr.Textbox(label="NAME (Link will be: repo-NAME.hf.space)")
|
179 |
+
t_space = gr.Textbox(label="Direct URL to your Space (https://you-repo-you-space.hf.space)")
|
180 |
+
t_title = gr.Textbox(label="Title for Twitter Card")
|
181 |
+
t_description = gr.Textbox(label="Short Description for Twitter Card")
|
182 |
+
t_redirect = gr.Textbox(label="Redirect URL for Twitter Card Click", placeholder="Optional Redirect URL")
|
183 |
+
gr.Markdown("""Image for your Card (min: 300x300 [Square]""")
|
184 |
+
t_image_url = gr.Textbox(label="Image URL", placeholder="Optional URL of Image")
|
185 |
+
t_image = gr.Image(label="Twitter Card Image", type="filepath",interactive=True)
|
186 |
+
with gr.Row():
|
187 |
+
input_button = gr.Button()
|
188 |
+
def_im = gr.Button("Load Default Image")
|
189 |
+
output_html = gr.HTML("""""")
|
190 |
+
gr.Column(scale=1)
|
191 |
+
input_button.click(build_space,[t_name,t_space,t_title,t_description,t_redirect,t_image,t_image_url,option_token],output_html)
|
192 |
+
def_im.click(d_im,None,t_image)
|
193 |
+
build_app.queue(concurrency_count=10).launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
opencv-python
|
sauce.css
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#component-1{
|
2 |
+
color:white;
|
3 |
+
}
|
4 |
+
#component-5{
|
5 |
+
background:linear-gradient(337deg, #1f2937, #324974);
|
6 |
+
color:white;
|
7 |
+
}
|
8 |
+
#component-6{
|
9 |
+
color:white;
|
10 |
+
}
|
11 |
+
#component-7{
|
12 |
+
background:#3d5a8f;
|
13 |
+
color:white;
|
14 |
+
}
|
15 |
+
#component-8{
|
16 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
17 |
+
color:white;
|
18 |
+
}
|
19 |
+
#component-9{
|
20 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
21 |
+
color:white;
|
22 |
+
}
|
23 |
+
#component-10{
|
24 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
25 |
+
color:white;
|
26 |
+
}
|
27 |
+
#component-11{
|
28 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
29 |
+
color:white;
|
30 |
+
}
|
31 |
+
#component-12{
|
32 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
33 |
+
color:white;
|
34 |
+
}
|
35 |
+
#component-13{
|
36 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
37 |
+
color:white;
|
38 |
+
}
|
39 |
+
#component-14{
|
40 |
+
color:white;
|
41 |
+
}
|
42 |
+
#component-15{
|
43 |
+
background:linear-gradient(90deg, #00000038, #6495ed26);
|
44 |
+
color:white;
|
45 |
+
}
|
46 |
+
#component-16{
|
47 |
+
background:#3a588f;
|
48 |
+
color:white;
|
49 |
+
}
|
50 |
+
#component-18{
|
51 |
+
background:radial-gradient(#6495ed26,#00000091);
|
52 |
+
color:white;
|
53 |
+
}
|
54 |
+
#component-19{
|
55 |
+
background:radial-gradient(#6495ed26,#00000091);
|
56 |
+
color:white;
|
57 |
+
}
|
58 |
+
.gradio-container-3-19-1 .prose *{
|
59 |
+
color:white;
|
60 |
+
}
|
61 |
+
.app.svelte-1cuuugq>.main.svelte-1cuuugq{
|
62 |
+
background:radial-gradient(circle farthest-side, #c5d6f5, #324975);
|
63 |
+
}
|
64 |
+
.gradio-container-3-19-1 .prose h1{
|
65 |
+
color:white;
|
66 |
+
}
|
67 |
+
.wrap.svelte-1hmcgg5{
|
68 |
+
color:white;
|
69 |
+
}
|
70 |
+
span.svelte-1l2rj76{
|
71 |
+
color:white;
|
72 |
+
}
|
73 |
+
div.svelte-1fwqiwq{
|
74 |
+
border:none;
|
75 |
+
}
|
76 |
+
div.svelte-1fwqiwq{
|
77 |
+
background:none;
|
78 |
+
}
|
79 |
+
.gradio-container-3-19-1 .prose>*:first-child{
|
80 |
+
color:white;
|
81 |
+
}
|
82 |
+
footer.svelte-t2gwjj.svelte-t2gwjj.svelte-t2gwjj{
|
83 |
+
color:white;
|
84 |
+
}
|
template/Default-AI.png
ADDED
![]() |
template/ai.html
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width" />
|
6 |
+
<meta name="twitter:card" content="player"/>
|
7 |
+
<meta name="twitter:site" content=""/>
|
8 |
+
<meta name="twitter:player" content="$space"/>
|
9 |
+
<meta name="twitter:player:stream" content="$space"/>
|
10 |
+
<meta name="twitter:player:width" content="100%"/>
|
11 |
+
<meta name="twitter:player:height" content="100%"/>
|
12 |
+
<meta property="og:title" content="$title"/>
|
13 |
+
<meta property="og:description" content="$description"/>
|
14 |
+
<meta property="og:image" content="$image"/>
|
15 |
+
<meta http-equiv="refresh" content="0; url=$redirect">
|
16 |
+
</head>
|
17 |
+
<body>
|
18 |
+
</body>
|
19 |
+
</html>
|
template/ai_demo_card.png
ADDED
![]() |
template/back.html
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
|
5 |
+
<style>
|
6 |
+
.container {
|
7 |
+
position: relative;
|
8 |
+
overflow: hidden;
|
9 |
+
width: 100%;
|
10 |
+
padding-top: 100%; /* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */
|
11 |
+
}
|
12 |
+
.responsive-iframe {
|
13 |
+
position: absolute;
|
14 |
+
top: 0;
|
15 |
+
left: 0;
|
16 |
+
bottom: 0;
|
17 |
+
right: 0;
|
18 |
+
width: 100%;
|
19 |
+
height: 100%;
|
20 |
+
}
|
21 |
+
</style>
|
22 |
+
</head>
|
23 |
+
<body>
|
24 |
+
<div class="container">
|
25 |
+
<iframe
|
26 |
+
class="responsive-iframe"
|
27 |
+
src="$iframe"
|
28 |
+
frameborder="0"
|
29 |
+
></iframe>
|
30 |
+
</div>
|
31 |
+
|
32 |
+
</body>
|
33 |
+
</html>
|
template/front.html
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
</head>
|
5 |
+
<body>
|
6 |
+
<iframe
|
7 |
+
src="$iframe"
|
8 |
+
frameborder="0"
|
9 |
+
width="100%"
|
10 |
+
height="2000"
|
11 |
+
></iframe>
|
12 |
+
</body>
|
13 |
+
</html>
|