widefirst103 commited on
Commit
bb3dda2
Β·
verified Β·
1 Parent(s): b5ac9f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -19
app.py CHANGED
@@ -1,25 +1,45 @@
1
- from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
2
  import gradio as gr
 
3
 
4
- model_name = "nlpai-lab/kobert-base-v1"
5
- tokenizer = AutoTokenizer.from_pretrained(model_name)
6
- model = AutoModelForQuestionAnswering.from_pretrained(model_name)
 
 
 
7
 
8
- generator = pipeline("text-generation", model="beomi/KoAlpaca-Polyglot-5.8B", device_map="auto")
 
 
 
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- context = """
12
- 수λŠ₯은 λ§€λ…„ 11μ›” μ…‹μ§Έ μ£Ό λͺ©μš”일에 μ‹œν–‰λ©λ‹ˆλ‹€.
13
- ν•œκ΅­μž₯ν•™μž¬λ‹¨μ€ λŒ€ν•™μƒμ—κ²Œ κ΅­κ°€μž₯ν•™κΈˆκ³Ό ν•™μžκΈˆλŒ€μΆœμ„ μ œκ³΅ν•©λ‹ˆλ‹€.
14
- μ •μ‹œλͺ¨μ§‘은 수λŠ₯ 성적 μœ„μ£Όλ‘œ, μˆ˜μ‹œλͺ¨μ§‘은 ν•™μƒλΆ€λ‚˜ λ©΄μ ‘μœΌλ‘œ μ„ λ°œν•©λ‹ˆλ‹€.
15
- """
 
 
 
 
 
 
 
 
16
 
17
- def answer(question):
18
- result = qa_pipeline(question=question, context=context)
19
- return result["answer"]
20
-
21
- gr.Interface(fn=answer,
22
- inputs="text",
23
- outputs="text",
24
- title="μž…μ‹œ λ„μš°λ―Έ AI",
25
- description="μž…μ‹œ κ΄€λ ¨ μ§ˆλ¬Έμ„ ν•΄λ³΄μ„Έμš”. 예: '수λŠ₯은 μ–Έμ œμ•Ό?'").launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # βœ… ν•œκ΅­μ–΄ κ²½λŸ‰ λͺ¨λΈ (λΉ λ₯΄κ³  곡개됨)
5
+ generator = pipeline(
6
+ "text-generation",
7
+ model="EleutherAI/polyglot-ko-1.3b",
8
+ device_map="auto"
9
+ )
10
 
11
+ # βœ… μž…μ‹œ 정보 응닡 ν•¨μˆ˜
12
+ def college_ai(question):
13
+ prompt = f"""λ„ˆλŠ” ν•œκ΅­ μž…μ‹œ μ „λ¬Έκ°€μ•Ό.
14
+ 학생이 μ§ˆλ¬Έν•˜λ©΄ κ°„κ²°ν•˜κ³  μ •ν™•ν•˜κ²Œ μ„€λͺ…ν•΄μ€˜.
15
+ κ°€λŠ₯ν•˜λ©΄ λŒ€ν•™λͺ…, μ „ν˜•λͺ…, λ°˜μ˜λΉ„μœ¨, 경쟁λ₯  같은 μ‹€μ œ 정보λ₯Ό ν¬ν•¨ν•΄μ€˜.
16
 
17
+ 질문: {question}
18
+ λ‹΅λ³€:"""
19
+ response = generator(
20
+ prompt,
21
+ max_new_tokens=200,
22
+ do_sample=True,
23
+ temperature=0.7,
24
+ top_p=0.9,
25
+ repetition_penalty=1.1
26
+ )
27
+ answer = response[0]["generated_text"].split("λ‹΅λ³€:")[-1].strip()
28
+ return answer
29
 
30
+ # βœ… Gradio μΈν„°νŽ˜μ΄μŠ€
31
+ demo = gr.Interface(
32
+ fn=college_ai,
33
+ inputs=gr.Textbox(
34
+ lines=2,
35
+ placeholder="예: ν•œκ΅­κ³΅ν•™λŒ€ 학생뢀ꡐ과 μ „ν˜• 경쟁λ₯  μ•Œλ €μ€˜",
36
+ label="μž…μ‹œ κ΄€λ ¨ 질문 μž…λ ₯"
37
+ ),
38
+ outputs=gr.Textbox(label="AI λ‹΅λ³€"),
39
+ title="πŸŽ“ μž…μ‹œμ •λ³΄ AI (College Info Assistant)",
40
+ description="ν•œκ΅­ λŒ€ν•™ μž…μ‹œ, 학생뢀쒅합, λ…Όμˆ , ꡐ과 μ „ν˜• 정보λ₯Ό μ•Œλ €μ£ΌλŠ” 인곡지λŠ₯μž…λ‹ˆλ‹€.",
41
+ theme="default"
42
+ )
43
 
44
+ if __name__ == "__main__":
45
+ demo.launch()