CSAT / app.py
widefirst103's picture
Update app.py
4ce373c verified
from transformers import pipeline
import gradio as gr
# ๋น ๋ฅธ ํ•œ๊ตญ์–ด GPT-2 ๋ชจ๋ธ ๋กœ๋“œ
generator = pipeline(
"text-generation",
model="skt/kogpt2-base-v2",
tokenizer="skt/kogpt2-base-v2"
)
def answer_question(prompt):
system_prompt = (
"๋„ˆ๋Š” ํ•œ๊ตญ ์ž…์‹œ์ •๋ณด๋ฅผ ์•Œ๋ ค์ฃผ๋Š” AI์•ผ. "
"์งˆ๋ฌธ์— ๋งž๊ฒŒ ๊ฐ„๋‹จ๋ช…๋ฃŒํ•˜๊ฒŒ ์„ค๋ช…ํ•ด์ค˜.\n\n"
)
response = generator(
system_prompt + prompt,
max_new_tokens=150,
temperature=0.7,
top_p=0.9,
do_sample=True
)
return response[0]["generated_text"].replace(system_prompt, "").strip()
app = gr.Interface(
fn=answer_question,
inputs=gr.Textbox(
lines=2,
label="์ž…์‹œ ์งˆ๋ฌธ ์ž…๋ ฅ",
placeholder="์˜ˆ: ์ˆ˜๋Šฅ ์ผ์ • / ํ•œ๊ตญ๊ณตํ•™๋Œ€ ๋…ผ์ˆ ์ „ํ˜• / ๊ฐ€์ฒœ๋Œ€ ๋ชจ์ง‘์ธ์›"
),
outputs=gr.Textbox(label="AI ๋‹ต๋ณ€"),
title="์ž…์‹œ์ •๋ณด AI (๋น ๋ฅธ ๋ฒ„์ „)",
description="CPU์—์„œ๋„ ๋น ๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๋Š” ์ž…์‹œ์ „๋ฌธ ์ฑ—๋ด‡์ž…๋‹ˆ๋‹ค."
)
if __name__ == "__main__":
app.launch()