widefirst103 commited on
Commit
e6e9f4b
Β·
verified Β·
1 Parent(s): 7254548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -1,18 +1,32 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def answer(question):
4
- if "수λŠ₯" in question:
5
- return "수λŠ₯은 λ§€λ…„ 11μ›” μ…‹μ§Έ μ£Ό λͺ©μš”일에 μ‹œν–‰λΌμš”."
6
- elif "ν•œκ΅­μž₯ν•™μž¬λ‹¨" in question:
7
- return "ν•œκ΅­μž₯ν•™μž¬λ‹¨μ€ κ΅­κ°€μž₯ν•™κΈˆκ³Ό ν•™μžκΈˆλŒ€μΆœμ„ μš΄μ˜ν•˜λŠ” κΈ°κ΄€μ΄μ—μš”."
8
- elif "지원" in question:
9
- return "지원은 λŒ€ν•™ μž…μ‹œμ—μ„œ νŠΉμ • ν•™κ³Όλ‚˜ 학ꡐ에 μ›μ„œλ₯Ό λ‚΄λŠ” κ±Έ λ§ν•΄μš”."
10
- else:
11
- return "κ·Έ μ§ˆλ¬Έμ€ 아직 λͺ°λΌμš”. λ‹€λ₯Έ μ§ˆλ¬Έμ„ ν•΄μ£Όμ„Έμš”!"
12
 
13
- gr.Interface(fn=answer,
14
- inputs="text",
15
- outputs="text",
16
- title="μž…μ‹œ λ„μš°λ―Έ AI",
17
- description="μž…μ‹œ κ΄€λ ¨ κΈ°λ³Έ 정보λ₯Ό μ•Œλ €μ£ΌλŠ” κ°„λ‹¨ν•œ AIμž…λ‹ˆλ‹€."
 
18
  ).launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
3
+
4
+ # λͺ¨λΈκ³Ό ν† ν¬λ‚˜μ΄μ € 뢈러였기
5
+ model_name = "nlpai-lab/kobert-base-v1"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
+
9
+ # μ§ˆλ¬Έμ‘λ‹΅ νŒŒμ΄ν”„λΌμΈ 생성
10
+ qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
11
+
12
+ # μž„μ‹œ μ˜ˆμ‹œ λ¬Έλ§₯ (λ‚˜μ€‘μ— μž…μ‹œ μ •λ³΄λ‘œ ꡐ체 κ°€λŠ₯)
13
+ context = """
14
+ ν•œκ΅­μž₯ν•™μž¬λ‹¨μ€ κ΅­κ°€μž₯ν•™κΈˆκ³Ό ν•™μžκΈˆλŒ€μΆœ 등을 κ΄€λ¦¬ν•˜λŠ” κΈ°κ΄€μž…λ‹ˆλ‹€.
15
+ 수λŠ₯은 λ§€λ…„ 11μ›” μ…‹μ§Έ μ£Ό λͺ©μš”일에 μ‹œν–‰λ©λ‹ˆλ‹€.
16
+ μ •μ‹œλͺ¨μ§‘은 수λŠ₯ 성적 μœ„μ£Όλ‘œ μ„ λ°œν•˜λ©°, μˆ˜μ‹œλͺ¨μ§‘은 ν•™μƒλΆ€λ‚˜ λ©΄μ ‘ λ“± λ‹€μ–‘ν•œ μ „ν˜•μ„ ν¬ν•¨ν•©λ‹ˆλ‹€.
17
+ """
18
 
19
  def answer(question):
20
+ try:
21
+ result = qa_pipeline(question=question, context=context)
22
+ return result["answer"]
23
+ except:
24
+ return "μ£„μ†‘ν•©λ‹ˆλ‹€. κ·Έ μ§ˆλ¬Έμ— λŒ€ν•œ 닡을 μ°Ύμ§€ λͺ»ν–ˆμ–΄μš”."
 
 
 
25
 
26
+ gr.Interface(
27
+ fn=answer,
28
+ inputs="text",
29
+ outputs="text",
30
+ title="μž…μ‹œ λ„μš°λ―Έ AI (KoBERT)",
31
+ description="ν•œκ΅­μ–΄ KoBERT λͺ¨λΈμ„ μ‚¬μš©ν•œ μž…μ‹œ 정보 Q&A AIμž…λ‹ˆλ‹€."
32
  ).launch()