widefirst103 commited on
Commit
209a482
Β·
verified Β·
1 Parent(s): 940c5d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -33
app.py CHANGED
@@ -1,46 +1,42 @@
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()
 
 
1
  from transformers import pipeline
2
+ import gradio as gr
3
 
4
+ # ν•œκ΅­μ–΄ μΈμŠ€νŠΈλŸ­μ…˜ λͺ¨λΈ λ‘œλ“œ
5
  generator = pipeline(
6
  "text-generation",
7
+ model="lemon-mint/gemma-ko-2b-instruct-v0.51",
8
+ tokenizer="lemon-mint/gemma-ko-2b-instruct-v0.51",
9
  device_map="auto"
10
  )
11
 
12
+ # μž…μ‹œ 정보 응닡 ν•¨μˆ˜
13
+ def answer_question(prompt):
14
+ system_prompt = (
15
+ "λ„ˆλŠ” ν•œκ΅­ λŒ€ν•™ μž…μ‹œ μ „λ¬Έκ°€ AIμ•Ό. "
16
+ "수λŠ₯, 학생뢀 μ’…ν•©μ „ν˜•, λ…Όμˆ , μ •μ‹œ λ“± λͺ¨λ“  μ „ν˜•μ„ μ‰½κ²Œ μ„€λͺ…ν•΄μ€˜. "
17
+ "κ°€λŠ₯ν•˜λ©΄ 학ꡐλͺ…, μ „ν˜•λͺ…, 지원쑰건 등을 ꡬ체적으둜 μ•Œλ €μ€˜.\n\n"
18
+ )
19
+ result = generator(
20
+ system_prompt + prompt,
21
+ max_new_tokens=300,
 
 
22
  temperature=0.7,
23
  top_p=0.9,
 
24
  do_sample=True
25
+ )
26
+ return result[0]["generated_text"].replace(system_prompt, "").strip()
27
 
28
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
29
+ app = gr.Interface(
30
+ fn=answer_question,
31
+ inputs=gr.Textbox(
32
+ lines=2,
33
+ label="μž…μ‹œ κ΄€λ ¨ 질문 μž…λ ₯",
34
+ placeholder="예: 2025 수λŠ₯ 일정 μ•Œλ €μ€˜ / κ°€μ²œλŒ€ 학생뢀 μ’…ν•©μ „ν˜• μ„€λͺ…"
35
+ ),
36
+ outputs=gr.Textbox(label="AI λ‹΅λ³€"),
37
+ title="μž…μ‹œ μ „λ¬Έ AI 챗봇",
38
+ description="ν•œκ΅­ λŒ€ν•™ μž…μ‹œ 정보λ₯Ό μ•Œλ €μ£ΌλŠ” μ±—λ΄‡μž…λ‹ˆλ‹€. μˆ˜μ‹œ, μ •μ‹œ, λ…Όμˆ  λ“± λͺ¨λ“  μ „ν˜•μ„ μ‰½κ²Œ μ„€λͺ…ν•΄μ€λ‹ˆλ‹€."
39
+ )
 
 
40
 
 
41
  if __name__ == "__main__":
42
+ app.launch()