Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
generator = pipeline(
|
| 6 |
"text-generation",
|
| 7 |
-
model="
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
๋ต๋ณ:"""
|
| 18 |
|
|
|
|
| 19 |
response = generator(
|
| 20 |
prompt,
|
| 21 |
-
max_new_tokens=
|
| 22 |
-
|
| 23 |
-
temperature=0.8,
|
| 24 |
top_p=0.9,
|
| 25 |
-
repetition_penalty=1.
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
title="๐ ์
์์ ๋ณด AI (๋น ๋ฅธ ๋ฒ์ )",
|
| 41 |
-
description="ํ๊ตญ ๋ํ ์
์, ํ์๋ถ๊ต๊ณผยท์ข
ํฉยท๋
ผ์ ์ ํ ๊ด๋ จ ์ ๋ณด๋ฅผ ๋น ๋ฅด๊ฒ ์๋ ค์ฃผ๋ ์ธ๊ณต์ง๋ฅ์
๋๋ค.",
|
| 42 |
-
theme="default"
|
| 43 |
-
)
|
| 44 |
|
|
|
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# KoAlpaca ๋ชจ๋ธ ๋ก๋
|
| 5 |
generator = pipeline(
|
| 6 |
"text-generation",
|
| 7 |
+
model="beomi/KoAlpaca-Polyglot-1.1B",
|
| 8 |
+
device_map="auto"
|
| 9 |
)
|
| 10 |
|
| 11 |
+
# ์๋ต ํจ์ ์ ์
|
| 12 |
+
def chat_with_koalpaca(message, history):
|
| 13 |
+
if history is None:
|
| 14 |
+
history = []
|
| 15 |
+
# ๋ํ ๋งฅ๋ฝ์ ๊ฐ๋จํ ํฉ์น๊ธฐ
|
| 16 |
+
context = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history])
|
| 17 |
+
prompt = f"{context}\nUser: {message}\nAssistant:"
|
|
|
|
| 18 |
|
| 19 |
+
# ๋ชจ๋ธ๋ก๋ถํฐ ์๋ต ์์ฑ
|
| 20 |
response = generator(
|
| 21 |
prompt,
|
| 22 |
+
max_new_tokens=200,
|
| 23 |
+
temperature=0.7,
|
|
|
|
| 24 |
top_p=0.9,
|
| 25 |
+
repetition_penalty=1.1,
|
| 26 |
+
do_sample=True
|
| 27 |
+
)[0]["generated_text"]
|
| 28 |
|
| 29 |
+
# ํ๋กฌํํธ ์ดํ ํ
์คํธ๋ง ์ถ์ถ
|
| 30 |
+
answer = response.split("Assistant:")[-1].strip()
|
| 31 |
+
history.append((message, answer))
|
| 32 |
+
return answer, history
|
| 33 |
|
| 34 |
+
# Gradio ์ธํฐํ์ด์ค
|
| 35 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 36 |
+
gr.Markdown("## ๐ฆ KoAlpaca Chatbot (Polyglot 1.1B)")
|
| 37 |
+
chatbot = gr.Chatbot(label="KoAlpaca")
|
| 38 |
+
msg = gr.Textbox(label="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์", placeholder="์: ์๋
! ์ค๋ ๋ ์จ ์ด๋?")
|
| 39 |
+
clear = gr.Button("๋ํ ์ด๊ธฐํ")
|
| 40 |
+
|
| 41 |
+
msg.submit(chat_with_koalpaca, [msg, chatbot], [msg, chatbot])
|
| 42 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# ์ฑ ์คํ
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|