Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,99 +1,44 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
import os
|
4 |
import requests
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
try:
|
13 |
-
|
14 |
-
|
15 |
-
except FileNotFoundError:
|
16 |
-
return f"{filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
17 |
except Exception as e:
|
18 |
-
return f"
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
system_message="", # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
28 |
-
max_tokens=1024, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
29 |
-
temperature=0.7, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
30 |
-
top_p=0.9, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
31 |
-
):
|
32 |
-
global fashion_code, uhdimage_code, MixGEN_code
|
33 |
-
system_message = system_message or ""
|
34 |
-
system_prefix = """๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ. ๋๋ ์ฃผ์ด์ง ์์ค์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก \"์๋น์ค ์ฌ์ฉ ์ค๋ช
๋ฐ ์๋ด, qna๋ฅผ ํ๋ ์ญํ ์ด๋ค\". ์์ฃผ ์น์ ํ๊ณ ์์ธํ๊ฒ 4000ํ ํฐ ์ด์ ์์ฑํ๋ผ. ๋๋ ์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฌ์ฉ ์ค๋ช
๋ฐ ์ง์ ์๋ต์ ์งํํ๋ฉฐ, ์ด์ฉ์์๊ฒ ๋์์ ์ฃผ์ด์ผ ํ๋ค. ์ด์ฉ์๊ฐ ๊ถ๊ธํด ํ ๋ง ํ ๋ด์ฉ์ ์น์ ํ๊ฒ ์๋ ค์ฃผ๋๋ก ํ๋ผ. ์ฝ๋ ์ ์ฒด ๋ด์ฉ์ ๋ํด์๋ ๋ณด์์ ์ ์งํ๊ณ , ํค ๊ฐ ๋ฐ ์๋ํฌ์ธํธ์ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์ ๊ณต๊ฐํ์ง ๋ง๋ผ. """
|
35 |
-
|
36 |
-
if message.lower() == "ํจ์
์ฝ๋ ์คํ":
|
37 |
-
system_message += f"\n\nํจ์
์ฝ๋ ๋ด์ฉ:\n{fashion_code}"
|
38 |
-
message = "ํจ์
๊ฐ์ํผํ
์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://aiqcamp-fash.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
39 |
-
elif message.lower() == "uhd ์ด๋ฏธ์ง ์ฝ๋ ์คํ":
|
40 |
-
system_message += f"\n\nUHD ์ด๋ฏธ์ง ์ฝ๋ ๋ด์ฉ:\n{uhdimage_code}"
|
41 |
-
message = "UHD ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-ultpixgen.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
42 |
-
elif message.lower() == "mixgen ์ฝ๋ ์คํ":
|
43 |
-
system_message += f"\n\nMixGEN ์ฝ๋ ๋ด์ฉ:\n{MixGEN_code}"
|
44 |
-
message = "MixGEN3 ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-mixgen3.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
45 |
-
|
46 |
-
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
47 |
-
for val in history:
|
48 |
-
if val[0]:
|
49 |
-
messages.append({"role": "user", "content": val[0]})
|
50 |
-
if val[1]:
|
51 |
-
messages.append({"role": "assistant", "content": val[1]})
|
52 |
-
messages.append({"role": "user", "content": message})
|
53 |
-
|
54 |
-
response = ""
|
55 |
-
for message in hf_client.chat_completion(
|
56 |
-
messages,
|
57 |
-
max_tokens=max_tokens,
|
58 |
-
stream=True,
|
59 |
-
temperature=temperature,
|
60 |
-
top_p=top_p,
|
61 |
-
):
|
62 |
-
token = message.choices[0].delta.get('content', None)
|
63 |
-
if token:
|
64 |
-
response += token.strip("")
|
65 |
-
yield response
|
66 |
-
|
67 |
-
css = """
|
68 |
-
footer {
|
69 |
-
visibility: hidden;
|
70 |
-
}
|
71 |
-
"""
|
72 |
-
|
73 |
-
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ถ๋ถ๋ ์์
|
74 |
-
demo = gr.ChatInterface(
|
75 |
-
respond,
|
76 |
-
additional_inputs=[
|
77 |
-
gr.Textbox(label="System Message", value=""),
|
78 |
-
gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens"),
|
79 |
-
gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
|
80 |
-
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
|
81 |
-
],
|
82 |
-
examples=[
|
83 |
-
["ํจ์
์ฝ๋ ์คํ"],
|
84 |
-
["UHD ์ด๋ฏธ์ง ์ฝ๋ ์คํ"],
|
85 |
-
["MixGEN ์ฝ๋ ์คํ"],
|
86 |
-
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
87 |
-
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
88 |
-
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
89 |
-
["๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
|
90 |
-
["ํนํ ์ถ์์ ํ์ฉํ ๊ธฐ์ ๋ฐ ๋น์ฆ๋์ค๋ชจ๋ธ ์ธก๋ฉด์ ํฌํจํ์ฌ ํนํ ์ถ์์ ๊ตฌ์ฑ์ ๋ง๊ฒ ํ์ ์ ์ธ ์ฐฝ์ ๋ฐ๋ช
๋ด์ฉ์ ์ค์ฌ์ผ๋ก 4000ํ ํฐ ์ด์ ์์ฑํ๋ผ."],
|
91 |
-
["๊ณ์ ์ด์ด์ ๋ต๋ณํ๋ผ"],
|
92 |
-
],
|
93 |
-
css=css,
|
94 |
-
theme="Nymbo/Nymbo_Theme",
|
95 |
-
cache_examples=False, # ์บ์ฑ ๋นํ์ฑํ ์ค์
|
96 |
)
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
-
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import gradio as gr
|
3 |
+
from typing import List, Dict
|
4 |
+
|
5 |
+
def get_most_liked_spaces(limit: int = 10) -> List[Dict]:
|
6 |
+
url = "https://huggingface.co/api/spaces"
|
7 |
+
params = {
|
8 |
+
"sort": "likes",
|
9 |
+
"direction": -1,
|
10 |
+
"limit": limit,
|
11 |
+
"full": "true"
|
12 |
+
}
|
13 |
+
|
14 |
+
response = requests.get(url, params=params)
|
15 |
+
response.raise_for_status()
|
16 |
+
|
17 |
+
return response.json()
|
18 |
+
|
19 |
+
def format_spaces(spaces: List[Dict]) -> str:
|
20 |
+
output = ""
|
21 |
+
for idx, space in enumerate(spaces, 1):
|
22 |
+
output += f"{idx}. {space['name']} by {space['author']}\n"
|
23 |
+
output += f" Likes: {space['likes']}\n"
|
24 |
+
output += f" URL: https://huggingface.co/spaces/{space['id']}\n\n"
|
25 |
+
return output
|
26 |
+
|
27 |
+
def get_spaces_list(limit: int) -> str:
|
28 |
try:
|
29 |
+
spaces = get_most_liked_spaces(limit)
|
30 |
+
return format_spaces(spaces)
|
|
|
|
|
31 |
except Exception as e:
|
32 |
+
return f"An error occurred: {str(e)}"
|
33 |
+
|
34 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=get_spaces_list,
|
37 |
+
inputs=gr.Slider(minimum=1, maximum=50, step=1, label="Number of Spaces to Display", value=10),
|
38 |
+
outputs="text",
|
39 |
+
title="Hugging Face Most Liked Spaces",
|
40 |
+
description="Display the most liked Hugging Face Spaces in descending order.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
+
iface.launch()
|