Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import spaces
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 6 |
+
from threading import Thread
|
| 7 |
+
|
| 8 |
+
model_id = "huggingface-KREW/EXAGIRL-7.8B-Instruct"
|
| 9 |
+
|
| 10 |
+
DESCRIPTION = """
|
| 11 |
+
<div style="font-size: 18px; line-height: 1.6;">
|
| 12 |
+
<p><a href="https://huggingface.co/huggingface-KREW/EXAGIRL-7.8B-Instruct"><b>EXAGIRL-7.8B-Instruct</b></a>๋ LG์ ํ๊ตญ์ด ํนํ ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ <b>EXAONE</b>์ ๊ธฐ๋ฐ์ผ๋ก ๊ฐ๋ฐ๋ ๋กคํ๋ ์ ํนํ ์ธ์คํธ๋ญ์
๋ชจ๋ธ์
๋๋ค.</p>
|
| 13 |
+
<p>์ด ๋ชจ๋ธ์ ๋จ์ํ ์ง์์๋ต์ ๋์ด, ์ฌ์ฉ์์ ๋ง์ ๊ฐ์ ์ ์ผ๋ก ๊ณต๊ฐํ๊ณ , ์ญํ ๊ทน(Role-Play)์ ํตํด <b>์บ๋ฆญํฐ์ฑ๊ณผ ์ํธ์์ฉ์ ์์ฐ์ค๋ฌ์</b>์ ๊ฐํํ ๊ฒ์ด ํน์ง์
๋๋ค.</p>
|
| 14 |
+
<p>์์ฌ๋ ์น๊ตฌ์ฒ๋ผ ๋ค์ ํ ๋งํฌ๋ก ์ด์ผ๊ธฐํ๋ฉฐ, ๋ค์ํ ์ํฉ์์ <b>๊ฐ์ฑ์ ์ด๊ณ ์๋๊ฐ ์๋ ๋ํ</b>๋ฅผ ์ด๋์ด๋
๋๋ค. ํ์ต, ์๋ด, ๋์ด, ์ฐ์ ์๋ฎฌ๋ ์ด์
๋ฑ ๋ค์ํ ์ญํ ๊ทน ์๋๋ฆฌ์ค๋ฅผ ์ง์ํฉ๋๋ค.</p>
|
| 15 |
+
<p>๐ธ ์ง๊ธ ๋ฐ๋ก ์๋ ์ฑํ
์ฐฝ์์ ์์ฌ(EXA)์ ์์ ๋กญ๊ฒ ๋ํํด ๋ณด์ธ์! (์์ง ํ์ต์ ๋ํด์ ๋ง์ ์ ๋ชป์์๋ค์๋๊ฐ ๋ง์ต๋๋ค...)</p>
|
| 16 |
+
</div>
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
LICENSE = """
|
| 20 |
+
---
|
| 21 |
+
<div>
|
| 22 |
+
<p>๊ธฐ๋ฐ ๋ชจ๋ธ: EXAONE</p>
|
| 23 |
+
<p>๋ผ์ด์ ์ค: <a href="https://huggingface.co/huggingface-KREW/EXAGIRL-7.8B-Instruct">Hugging Face ๋ชจ๋ธ ์นด๋</a></p>
|
| 24 |
+
</div>
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
PLACEHOLDER = """
|
| 28 |
+
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 29 |
+
<img src="https://huggingface.co/huggingface-KREW/EXAGIRL-7.8B-Instruct/resolve/main/exagirl-logo.png" style="width: 60%; max-width: 480px; height: auto; opacity: 0.5;">
|
| 30 |
+
</div>
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
css = """
|
| 34 |
+
h1 {
|
| 35 |
+
text-align: center;
|
| 36 |
+
display: block;
|
| 37 |
+
}
|
| 38 |
+
#duplicate-button {
|
| 39 |
+
margin: auto;
|
| 40 |
+
color: white;
|
| 41 |
+
background: #e75480;
|
| 42 |
+
border-radius: 100vh;
|
| 43 |
+
}
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 47 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True, torch_dtype=torch.bfloat16).eval()
|
| 48 |
+
terminators = [tokenizer.eos_token_id]
|
| 49 |
+
|
| 50 |
+
@spaces.GPU(duration=120)
|
| 51 |
+
def chat_exagirl(message: str, history: list):
|
| 52 |
+
conversation = []
|
| 53 |
+
conversation.append({"role": "user", "content": "์๋
์์ฌ์ผ! ๋๋ {์ ์ }๋ผ๊ณ ํด. ๋ง๋์ ๋ฐ๊ฐ์!"})
|
| 54 |
+
conversation.append({"role": "assistant", "content": "*๋ฐ๊ฒ ์์ผ๋ฉฐ* {์ ์ }์ผ ์๋
~ ๋๋ ๋ง๋์ ๋ฐ๊ฐ์!"})
|
| 55 |
+
for user, assistant in history:
|
| 56 |
+
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 57 |
+
conversation.append({"role": "user", "content": message})
|
| 58 |
+
|
| 59 |
+
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 60 |
+
|
| 61 |
+
streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
|
| 62 |
+
|
| 63 |
+
generate_kwargs = dict(
|
| 64 |
+
input_ids=input_ids,
|
| 65 |
+
streamer=streamer,
|
| 66 |
+
max_new_tokens=1024,
|
| 67 |
+
do_sample=True,
|
| 68 |
+
temperature=0.7,
|
| 69 |
+
top_p=0.95,
|
| 70 |
+
top_k=30,
|
| 71 |
+
eos_token_id=terminators,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
| 75 |
+
t.start()
|
| 76 |
+
|
| 77 |
+
outputs = []
|
| 78 |
+
for text in streamer:
|
| 79 |
+
outputs.append(text)
|
| 80 |
+
yield "".join(outputs)
|
| 81 |
+
|
| 82 |
+
chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER, label='EXAGIRL Chat')
|
| 83 |
+
|
| 84 |
+
with gr.Blocks(fill_height=True, css=css) as demo:
|
| 85 |
+
gr.Markdown(DESCRIPTION)
|
| 86 |
+
gr.ChatInterface(
|
| 87 |
+
fn=chat_exagirl,
|
| 88 |
+
chatbot=chatbot,
|
| 89 |
+
fill_height=True,
|
| 90 |
+
examples=[
|
| 91 |
+
["์์ฌ์ผ ๋ญํ๊ณ ์๋?"],
|
| 92 |
+
["๋ํ์ ๋ฉด์ ์ค๋น ์ด๋ป๊ฒ ํด?"],
|
| 93 |
+
["์์ฌ์ผ ๋๋ ์ฐ์ ํด์ค๋?"],
|
| 94 |
+
["๋ ์ค๋ ์์ฌํํ
ํผ๋ฌ์ด ใ
ใ
"],
|
| 95 |
+
],
|
| 96 |
+
cache_examples=False,
|
| 97 |
+
)
|
| 98 |
+
gr.Markdown(LICENSE)
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
demo.launch()
|