Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import requests
|
|
|
5 |
|
6 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
7 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
|
@@ -18,33 +19,31 @@ def load_code(filename):
|
|
18 |
|
19 |
fashion_code = load_code('fashion.cod')
|
20 |
uhdimage_code = load_code('uhdimage.cod')
|
|
|
21 |
|
22 |
def respond(
|
23 |
message,
|
24 |
-
history:
|
25 |
system_message="", # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
26 |
max_tokens=1024, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
27 |
temperature=0.7, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
28 |
top_p=0.9, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
29 |
):
|
30 |
-
global fashion_code, uhdimage_code
|
31 |
-
|
|
|
32 |
|
33 |
if message.lower() == "ํจ์
์ฝ๋ ์คํ":
|
34 |
-
system_message = system_message or "" # None์ธ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด๋ก ์ด๊ธฐํ
|
35 |
system_message += f"\n\nํจ์
์ฝ๋ ๋ด์ฉ:\n{fashion_code}"
|
36 |
message = "ํจ์
๊ฐ์ํผํ
์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://aiqcamp-fash.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
37 |
elif message.lower() == "uhd ์ด๋ฏธ์ง ์ฝ๋ ์คํ":
|
38 |
-
system_message = system_message or "" # None์ธ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด๋ก ์ด๊ธฐํ
|
39 |
system_message += f"\n\nUHD ์ด๋ฏธ์ง ์ฝ๋ ๋ด์ฉ:\n{uhdimage_code}"
|
40 |
message = "UHD ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-ultpixgen.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
41 |
-
elif message.lower() == "
|
42 |
-
system_message = system_message or "" # None์ธ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด๋ก ์ด๊ธฐํ
|
43 |
system_message += f"\n\nMixGEN ์ฝ๋ ๋ด์ฉ:\n{MixGEN_code}"
|
44 |
message = "MixGEN3 ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-mixgen3.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
45 |
|
46 |
-
|
47 |
-
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] # prefix ์ถ๊ฐ
|
48 |
for val in history:
|
49 |
if val[0]:
|
50 |
messages.append({"role": "user", "content": val[0]})
|
@@ -60,9 +59,9 @@ def respond(
|
|
60 |
temperature=temperature,
|
61 |
top_p=top_p,
|
62 |
):
|
63 |
-
token = message.choices[0].delta.content
|
64 |
-
if token
|
65 |
-
response += token.strip("")
|
66 |
yield response
|
67 |
|
68 |
css = """
|
@@ -71,7 +70,6 @@ footer {
|
|
71 |
}
|
72 |
"""
|
73 |
|
74 |
-
|
75 |
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ถ๋ถ๋ ์์
|
76 |
demo = gr.ChatInterface(
|
77 |
respond,
|
@@ -84,7 +82,7 @@ demo = gr.ChatInterface(
|
|
84 |
examples=[
|
85 |
["ํจ์
์ฝ๋ ์คํ"],
|
86 |
["UHD ์ด๋ฏธ์ง ์ฝ๋ ์คํ"],
|
87 |
-
["
|
88 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
89 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
90 |
["๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
|
@@ -94,7 +92,6 @@ demo = gr.ChatInterface(
|
|
94 |
css=css,
|
95 |
theme="Nymbo/Nymbo_Theme",
|
96 |
cache_examples=False, # ์บ์ฑ ๋นํ์ฑํ ์ค์
|
97 |
-
# css="""footer {visibility: hidden}""", # ์ด๊ณณ์ CSS๋ฅผ ์ถ๊ฐ
|
98 |
)
|
99 |
|
100 |
if __name__ == "__main__":
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import requests
|
5 |
+
from typing import List, Tuple
|
6 |
|
7 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
8 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
|
|
|
19 |
|
20 |
fashion_code = load_code('fashion.cod')
|
21 |
uhdimage_code = load_code('uhdimage.cod')
|
22 |
+
MixGEN_code = load_code('mixgen.cod')
|
23 |
|
24 |
def respond(
|
25 |
message,
|
26 |
+
history: List[Tuple[str, str]],
|
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]})
|
|
|
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 = """
|
|
|
70 |
}
|
71 |
"""
|
72 |
|
|
|
73 |
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ถ๋ถ๋ ์์
|
74 |
demo = gr.ChatInterface(
|
75 |
respond,
|
|
|
82 |
examples=[
|
83 |
["ํจ์
์ฝ๋ ์คํ"],
|
84 |
["UHD ์ด๋ฏธ์ง ์ฝ๋ ์คํ"],
|
85 |
+
["MixGEN ์ฝ๋ ์คํ"],
|
86 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
87 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
88 |
["๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
|
|
|
92 |
css=css,
|
93 |
theme="Nymbo/Nymbo_Theme",
|
94 |
cache_examples=False, # ์บ์ฑ ๋นํ์ฑํ ์ค์
|
|
|
95 |
)
|
96 |
|
97 |
if __name__ == "__main__":
|