Spaces:
Running
Running
tripleS-Dev
commited on
Commit
β’
114df7a
1
Parent(s):
eb5f9ae
add discord login
Browse files- fns.py +3 -9
- generate.py +1 -1
- login_discord.py +69 -0
- main.py +27 -16
- requirements.txt +2 -1
fns.py
CHANGED
@@ -113,15 +113,9 @@ def refresh():
|
|
113 |
# νμ¬ μμ
λλ ν 리μ ν΄λ μ΄λ¦λ€μ ννλ‘ λ°ν (νΉμ ν΄λ μ μΈ)
|
114 |
return folders_tuple
|
115 |
|
116 |
-
def dev(
|
117 |
-
|
118 |
-
|
119 |
-
return "Do", gr.Dropdown(folders, visible=True, interactive=True), gr.File(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True)
|
120 |
-
elif a == "Whitehasthewrongonememberwhoisnotavailabletoyoursetupandthechoicesaregiveneveryyearforcharandcroptoyoursetupicontomakethechangesyouareusingmake":
|
121 |
-
os.makedirs("/data/cache")
|
122 |
-
return "Permission denied", gr.Dropdown(visible=False, interactive=False), gr.File(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False)
|
123 |
-
else:
|
124 |
-
return "Permission denied", gr.Dropdown(visible=False, interactive=False), gr.File(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False), gr.Button(visible=False, interactive=False)
|
125 |
|
126 |
|
127 |
def dev2():
|
|
|
113 |
# νμ¬ μμ
λλ ν 리μ ν΄λ μ΄λ¦λ€μ ννλ‘ λ°ν (νΉμ ν΄λ μ μΈ)
|
114 |
return folders_tuple
|
115 |
|
116 |
+
def dev():
|
117 |
+
folders = refresh()
|
118 |
+
return "Do", gr.Dropdown(folders, visible=True, interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
|
121 |
def dev2():
|
generate.py
CHANGED
@@ -433,7 +433,7 @@ def event(event_img, event_radio, event_txt, position):
|
|
433 |
f'/data/cache/event_{krtime}_{i1}.jpg',
|
434 |
quality=70)
|
435 |
# μ΄λ―Έμ§ 리μ€νΈμ μΆκ°
|
436 |
-
|
437 |
images_list.append(event_img_s)
|
438 |
|
439 |
|
|
|
433 |
f'/data/cache/event_{krtime}_{i1}.jpg',
|
434 |
quality=70)
|
435 |
# μ΄λ―Έμ§ 리μ€νΈμ μΆκ°
|
436 |
+
|
437 |
images_list.append(event_img_s)
|
438 |
|
439 |
|
login_discord.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import gradio as gr
|
3 |
+
from urllib.parse import urlparse, parse_qs
|
4 |
+
|
5 |
+
def id_check(request: gr.Request):
|
6 |
+
param = str(request.query_params)
|
7 |
+
if not param:
|
8 |
+
return "Login to Discord", gr.Tab(visible=False)
|
9 |
+
|
10 |
+
code = param.split('code=')
|
11 |
+
print(code[1])
|
12 |
+
|
13 |
+
user_id, username, avatar_url = get_discord_user_profile(str(code[1]))
|
14 |
+
if user_id == None:
|
15 |
+
return "Login to Discord", gr.Tab(visible=False)
|
16 |
+
if user_id == "412827396027187211":
|
17 |
+
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=True)
|
18 |
+
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=False)
|
19 |
+
|
20 |
+
|
21 |
+
def get_discord_user_profile(code):
|
22 |
+
# Discordμ API μλν¬μΈνΈ
|
23 |
+
token_url = "https://discord.com/api/oauth2/token"
|
24 |
+
user_url = "https://discord.com/api/users/@me"
|
25 |
+
|
26 |
+
try:
|
27 |
+
# ν ν° μμ²μ μν λ°μ΄ν°
|
28 |
+
data = {
|
29 |
+
'client_id': client_id, # client_id μ€μ
|
30 |
+
'client_secret': client_secret, # client_secret μ€μ
|
31 |
+
'grant_type': 'authorization_code',
|
32 |
+
'code': code,
|
33 |
+
'redirect_uri': redirect_uri # redirect_uri μ€μ
|
34 |
+
}
|
35 |
+
headers = {
|
36 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
37 |
+
}
|
38 |
+
|
39 |
+
# μ‘μΈμ€ ν ν° μμ²
|
40 |
+
token_response = requests.post(token_url, data=data, headers=headers)
|
41 |
+
token_response.raise_for_status() # μ€λ₯ λ°μμ μμΈ λ°μ
|
42 |
+
access_token = token_response.json().get('access_token')
|
43 |
+
|
44 |
+
# μ¬μ©μ μ 보 μμ²
|
45 |
+
auth_headers = {
|
46 |
+
'Authorization': f'Bearer {access_token}'
|
47 |
+
}
|
48 |
+
user_response = requests.get(user_url, headers=auth_headers)
|
49 |
+
user_response.raise_for_status() # μ€λ₯ λ°μμ μμΈ λ°μ
|
50 |
+
user_info = user_response.json()
|
51 |
+
|
52 |
+
user_id = user_info.get('id')
|
53 |
+
username = user_info.get('username') + '#' + user_info.get('discriminator')
|
54 |
+
avatar_hash = user_info.get('avatar')
|
55 |
+
avatar_url = f"https://cdn.discordapp.com/avatars/{user_id}/{avatar_hash}.png" if avatar_hash else None
|
56 |
+
|
57 |
+
return user_id, username, avatar_url
|
58 |
+
|
59 |
+
except requests.exceptions.RequestException as e:
|
60 |
+
print("Error to login")
|
61 |
+
# print(str(e)) # μ€λ₯ λ΄μ© μΆλ ₯μ μνλ€λ©΄ μ£Όμ ν΄μ
|
62 |
+
return None, None, None # μ€λ₯ λ°μμ None λ°ν
|
63 |
+
|
64 |
+
# μ¬μ© μ:
|
65 |
+
client_id = "1239473790732472370"
|
66 |
+
client_secret = "C7RLdB4YArSM9jVk8tsznQnKOzwGKwsO"
|
67 |
+
# code = "THE_CODE_FROM_REDIRECT_URI"
|
68 |
+
redirect_uri = "http://localhost:7860/"
|
69 |
+
|
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import fns
|
3 |
import generate
|
|
|
4 |
|
5 |
js_func = """
|
6 |
function refresh() {
|
@@ -12,15 +13,22 @@ function refresh() {
|
|
12 |
}
|
13 |
}
|
14 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
with gr.Blocks(theme=gr.themes.Soft(), js=js_func) as demo:
|
17 |
-
with gr.Row():
|
18 |
gr.Markdown(
|
19 |
"""
|
20 |
-
# Objektify
|
21 |
### custom objekt
|
22 |
-
|
23 |
-
"""
|
|
|
|
|
24 |
with gr.Tab("Event"):
|
25 |
with gr.Row():
|
26 |
with gr.Column():
|
@@ -31,7 +39,7 @@ with gr.Blocks(theme=gr.themes.Soft(), js=js_func) as demo:
|
|
31 |
event_position = gr.Slider(label="Y position", maximum=100, minimum=0)
|
32 |
event_generate = gr.Button(value="Generate")
|
33 |
with gr.Column():
|
34 |
-
event_output = gr.Gallery(label="output", interactive=False, type="pil", visible=True, scale=10)
|
35 |
event_generate.click(fn=generate.event, inputs=[event_img, event_radio, event_txt, event_position], outputs=event_output)
|
36 |
|
37 |
|
@@ -180,22 +188,22 @@ with gr.Blocks(theme=gr.themes.Soft(), js=js_func) as demo:
|
|
180 |
|
181 |
|
182 |
|
183 |
-
with gr.Tab("Dev"):
|
184 |
-
|
185 |
-
dev_btn = gr.Button(value="
|
186 |
dev_out = gr.Textbox()
|
187 |
-
dev_drop = gr.Dropdown(
|
188 |
-
dev_file = gr.File(
|
189 |
-
dev_btn2 = gr.Button(
|
190 |
-
dev_btn3 = gr.Button(
|
191 |
-
dev_btn4 = gr.Button(
|
192 |
-
dev_btn5 = gr.Button(
|
193 |
|
194 |
dev_btn2.click(fn=fns.dev2, outputs=dev_out)
|
195 |
dev_btn3.click(fn=fns.dev3, inputs=dev_drop, outputs=dev_out)
|
196 |
dev_btn4.click(fn=fns.dev4, inputs=dev_drop, outputs=dev_file)
|
197 |
dev_btn5.click(fn=fns.dev5, inputs=dev_drop, outputs=dev_out)
|
198 |
-
dev_btn.click(fns.dev,
|
199 |
gr.Markdown(
|
200 |
"""
|
201 |
## support email : ssscosmotest@gmail.com
|
@@ -227,6 +235,9 @@ with gr.Blocks(theme=gr.themes.Soft(), js=js_func) as demo:
|
|
227 |
right_btn, rounded_back], outputs=[preview, ex_img_b])
|
228 |
|
229 |
ex_btn.click(fn=generate.ex_gen, inputs=[ex_img_f, ex_file_f, ex_img_b, ex_gen_file_count, ex_hide_blur, ex_hide_blur_range, watermark], outputs=[ex_img_f_out, ex_img_b_out])
|
|
|
|
|
|
|
230 |
|
231 |
if __name__ == "__main__":
|
232 |
print("http://localhost:7860")
|
|
|
1 |
import gradio as gr
|
2 |
import fns
|
3 |
import generate
|
4 |
+
import login_discord
|
5 |
|
6 |
js_func = """
|
7 |
function refresh() {
|
|
|
13 |
}
|
14 |
}
|
15 |
"""
|
16 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo: # , js=js_func
|
17 |
+
with gr.Column():
|
18 |
+
with gr.Row():
|
19 |
+
gr.Markdown(
|
20 |
+
"""
|
21 |
+
# Objektify
|
22 |
+
""")
|
23 |
+
login = gr.Button(size="sm", value="Login to Discord", link="https://discord.com/oauth2/authorize?client_id=1239473790732472370&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A7860%2F&scope=identify", scale=0)
|
24 |
|
|
|
|
|
25 |
gr.Markdown(
|
26 |
"""
|
|
|
27 |
### custom objekt
|
28 |
+
## Input image and Select Options
|
29 |
+
"""
|
30 |
+
)
|
31 |
+
|
32 |
with gr.Tab("Event"):
|
33 |
with gr.Row():
|
34 |
with gr.Column():
|
|
|
39 |
event_position = gr.Slider(label="Y position", maximum=100, minimum=0)
|
40 |
event_generate = gr.Button(value="Generate")
|
41 |
with gr.Column():
|
42 |
+
event_output = gr.Gallery(label="output", interactive=False, type="pil", visible=True, scale=10, object_fit="scale-down")
|
43 |
event_generate.click(fn=generate.event, inputs=[event_img, event_radio, event_txt, event_position], outputs=event_output)
|
44 |
|
45 |
|
|
|
188 |
|
189 |
|
190 |
|
191 |
+
with gr.Tab("Dev", visible=False) as dev:
|
192 |
+
|
193 |
+
dev_btn = gr.Button(value="refresh", visible=True, interactive=True)
|
194 |
dev_out = gr.Textbox()
|
195 |
+
dev_drop = gr.Dropdown()
|
196 |
+
dev_file = gr.File()
|
197 |
+
dev_btn2 = gr.Button(value="move")
|
198 |
+
dev_btn3 = gr.Button(value="zip")
|
199 |
+
dev_btn4 = gr.Button(value="download")
|
200 |
+
dev_btn5 = gr.Button(value="remove")
|
201 |
|
202 |
dev_btn2.click(fn=fns.dev2, outputs=dev_out)
|
203 |
dev_btn3.click(fn=fns.dev3, inputs=dev_drop, outputs=dev_out)
|
204 |
dev_btn4.click(fn=fns.dev4, inputs=dev_drop, outputs=dev_file)
|
205 |
dev_btn5.click(fn=fns.dev5, inputs=dev_drop, outputs=dev_out)
|
206 |
+
dev_btn.click(fns.dev, outputs=[dev_out, dev_drop])
|
207 |
gr.Markdown(
|
208 |
"""
|
209 |
## support email : ssscosmotest@gmail.com
|
|
|
235 |
right_btn, rounded_back], outputs=[preview, ex_img_b])
|
236 |
|
237 |
ex_btn.click(fn=generate.ex_gen, inputs=[ex_img_f, ex_file_f, ex_img_b, ex_gen_file_count, ex_hide_blur, ex_hide_blur_range, watermark], outputs=[ex_img_f_out, ex_img_b_out])
|
238 |
+
demo.load(fn=login_discord.id_check, outputs=[login, dev])
|
239 |
+
|
240 |
+
|
241 |
|
242 |
if __name__ == "__main__":
|
243 |
print("http://localhost:7860")
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ gradio
|
|
2 |
numpy
|
3 |
Pillow
|
4 |
qrcode
|
5 |
-
pytz
|
|
|
|
2 |
numpy
|
3 |
Pillow
|
4 |
qrcode
|
5 |
+
pytz
|
6 |
+
requests
|