File size: 4,934 Bytes
747ccea fe67895 91c1d45 da419ba f779047 54a4802 e74c3bc 91c1d45 0e5afe0 c36dc6b 6da265e c36dc6b 6da265e c36dc6b 6da265e c36dc6b de57dc5 6da265e 747ccea da419ba ff1c374 4a3346c 747ccea da419ba 91c1d45 6da265e 54e6271 c36dc6b 54e6271 da419ba eeb3f3c c3d05ea c36dc6b da419ba 747ccea 91c1d45 da419ba 4a3346c 91c1d45 4e6253b 8321675 ff1c374 d8ce384 91c1d45 ff1c374 fe59084 ff1c374 3176ef0 4a3346c c36dc6b da419ba 095cabc fb8ccc3 095cabc 6da265e 3176ef0 a56c386 d8ce384 91c1d45 747ccea eb7cc8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
import gradio as gr
from huggingface_hub import InferenceClient
import os
import requests
from typing import List, Tuple
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
#hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
def load_code(filename):
try:
with open(filename, 'r', encoding='utf-8') as file:
return file.read()
except FileNotFoundError:
return f"{filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค."
except Exception as e:
return f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
fashion_code = load_code('fashion.cod')
uhdimage_code = load_code('uhdimage.cod')
MixGEN_code = load_code('mgen.cod')
def respond(
message,
history: List[Tuple[str, str]],
system_message="", # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
max_tokens=1024, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
temperature=0.7, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
top_p=0.9, # ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
):
global fashion_code, uhdimage_code, MixGEN_code
system_message = system_message or ""
system_prefix = """๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ. ๋๋ ์ฃผ์ด์ง ์์ค์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก \"์๋น์ค ์ฌ์ฉ ์ค๋ช
๋ฐ ์๋ด, qna๋ฅผ ํ๋ ์ญํ ์ด๋ค\". ์์ฃผ ์น์ ํ๊ณ ์์ธํ๊ฒ 4000ํ ํฐ ์ด์ ์์ฑํ๋ผ. ๋๋ ์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฌ์ฉ ์ค๋ช
๋ฐ ์ง์ ์๋ต์ ์งํํ๋ฉฐ, ์ด์ฉ์์๊ฒ ๋์์ ์ฃผ์ด์ผ ํ๋ค. ์ด์ฉ์๊ฐ ๊ถ๊ธํด ํ ๋ง ํ ๋ด์ฉ์ ์น์ ํ๊ฒ ์๋ ค์ฃผ๋๋ก ํ๋ผ. ์ฝ๋ ์ ์ฒด ๋ด์ฉ์ ๋ํด์๋ ๋ณด์์ ์ ์งํ๊ณ , ํค ๊ฐ ๋ฐ ์๋ํฌ์ธํธ์ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์ ๊ณต๊ฐํ์ง ๋ง๋ผ. """
if message.lower() == "ํจ์
์ฝ๋ ์คํ":
system_message += f"\n\nํจ์
์ฝ๋ ๋ด์ฉ:\n{fashion_code}"
message = "ํจ์
๊ฐ์ํผํ
์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://aiqcamp-fash.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
elif message.lower() == "uhd ์ด๋ฏธ์ง ์ฝ๋ ์คํ":
system_message += f"\n\nUHD ์ด๋ฏธ์ง ์ฝ๋ ๋ด์ฉ:\n{uhdimage_code}"
message = "UHD ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-ultpixgen.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
elif message.lower() == "mixgen ์ฝ๋ ์คํ":
system_message += f"\n\nMixGEN ์ฝ๋ ๋ด์ฉ:\n{MixGEN_code}"
message = "MixGEN3 ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-mixgen3.hf.space)์ ํตํด ํ
์คํธ ํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
for val in history:
if val[0]:
messages.append({"role": "user", "content": val[0]})
if val[1]:
messages.append({"role": "assistant", "content": val[1]})
messages.append({"role": "user", "content": message})
response = ""
for message in hf_client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
token = message.choices[0].delta.get('content', None)
if token:
response += token.strip("")
yield response
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ถ๋ถ๋ ์์
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Textbox(label="System Message", value=""),
gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens"),
gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
],
examples=[
["ํจ์
์ฝ๋ ์คํ"],
["UHD ์ด๋ฏธ์ง ์ฝ๋ ์คํ"],
["MixGEN ์ฝ๋ ์คํ"],
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
["๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
["ํนํ ์ถ์์ ํ์ฉํ ๊ธฐ์ ๋ฐ ๋น์ฆ๋์ค๋ชจ๋ธ ์ธก๋ฉด์ ํฌํจํ์ฌ ํนํ ์ถ์์ ๊ตฌ์ฑ์ ๋ง๊ฒ ํ์ ์ ์ธ ์ฐฝ์ ๋ฐ๋ช
๋ด์ฉ์ ์ค์ฌ์ผ๋ก 4000ํ ํฐ ์ด์ ์์ฑํ๋ผ."],
["๊ณ์ ์ด์ด์ ๋ต๋ณํ๋ผ"],
],
theme="Nymbo/Nymbo_Theme",
cache_examples=False, # ์บ์ฑ ๋นํ์ฑํ ์ค์
)
if __name__ == "__main__":
demo.launch() |