yongyeol commited on
Commit
7858545
Β·
verified Β·
1 Parent(s): 206f3b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -4,13 +4,13 @@ import requests
4
  from datetime import datetime
5
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
6
 
7
- # βœ… 1. KoAlpaca λͺ¨λΈ λ‘œλ“œ
8
- model_id = "beomi/KoAlpaca-Polyglot-5.8B"
9
  tokenizer = AutoTokenizer.from_pretrained(model_id)
10
  model = AutoModelForCausalLM.from_pretrained(model_id)
11
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
12
 
13
- # βœ… 2. NEIS API μ„€μ •
14
  NEIS_KEY = "a69e08342c8947b4a52cd72789a5ecaf"
15
  SCHOOL_INFO_URL = "https://open.neis.go.kr/hub/schoolInfo"
16
  SCHEDULE_URL = "https://open.neis.go.kr/hub/SchoolSchedule"
@@ -23,7 +23,6 @@ REGIONS = {
23
  MONTH_NAMES = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
24
 
25
 
26
- # βœ… 3. 학ꡐ μ½”λ“œ 쑰회
27
  def get_school_code(region_code, school_name):
28
  params = {
29
  "KEY": NEIS_KEY,
@@ -41,7 +40,6 @@ def get_school_code(region_code, school_name):
41
  return None, None
42
 
43
 
44
- # βœ… 4. 학사일정 쑰회
45
  def get_schedule(region_code, school_code, year, month):
46
  from_ymd = f"{year}{month}01"
47
  to_ymd = f"{year}{month}31"
@@ -58,15 +56,12 @@ def get_schedule(region_code, school_code, year, month):
58
  res = requests.get(SCHEDULE_URL, params=params)
59
  data = res.json()
60
  try:
61
- rows = data["SchoolSchedule"][1]["row"]
62
- return rows
63
  except:
64
  return []
65
 
66
 
67
- # βœ… 5. GPT 응닡 생성
68
  def generate_answer(region, school_name, year, month, question):
69
- # κΈ°λ³Έκ°’ 보정
70
  now = datetime.now()
71
  if not year:
72
  year = str(now.year)
@@ -98,18 +93,17 @@ def generate_answer(region, school_name, year, month, question):
98
  return result
99
 
100
 
101
- # βœ… 6. Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
102
  with gr.Interface(
103
  fn=generate_answer,
104
  inputs=[
105
  gr.Dropdown(choices=list(REGIONS.keys()), label="ꡐ윑청 선택"),
106
  gr.Textbox(label="학ꡐλͺ… μž…λ ₯"),
107
- gr.Textbox(label="년도 μž…λ ₯ (선택, 예: 2025)"),
108
- gr.Dropdown(choices=MONTH_NAMES, label="μ›” 선택 (선택, 예: 07)"),
109
  gr.Textbox(label="질문 μž…λ ₯ (예: 여름방학은 μ–Έμ œμ•Ό?)")
110
  ],
111
  outputs=gr.Textbox(label="GPT의 응닡"),
112
- title="πŸ“… 학사일정 + GPT 챗봇 (KoAlpaca)",
113
- description="학ꡐλͺ…κ³Ό μ§ˆλ¬Έμ„ μž…λ ₯ν•˜λ©΄ GPTκ°€ 학사일정 기반으둜 λŒ€λ‹΅ν•΄μ€λ‹ˆλ‹€. 연도/월은 λΉ„μ›Œλ‘λ©΄ 였늘 κΈ°μ€€μœΌλ‘œ μ²˜λ¦¬λ©λ‹ˆλ‹€."
114
  ) as app:
115
  app.launch()
 
4
  from datetime import datetime
5
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
6
 
7
+ # Load Google Gemma λͺ¨λΈ (2B)
8
+ model_id = "google/gemma-2b-it"
9
  tokenizer = AutoTokenizer.from_pretrained(model_id)
10
  model = AutoModelForCausalLM.from_pretrained(model_id)
11
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
12
 
13
+ # NEIS API
14
  NEIS_KEY = "a69e08342c8947b4a52cd72789a5ecaf"
15
  SCHOOL_INFO_URL = "https://open.neis.go.kr/hub/schoolInfo"
16
  SCHEDULE_URL = "https://open.neis.go.kr/hub/SchoolSchedule"
 
23
  MONTH_NAMES = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
24
 
25
 
 
26
  def get_school_code(region_code, school_name):
27
  params = {
28
  "KEY": NEIS_KEY,
 
40
  return None, None
41
 
42
 
 
43
  def get_schedule(region_code, school_code, year, month):
44
  from_ymd = f"{year}{month}01"
45
  to_ymd = f"{year}{month}31"
 
56
  res = requests.get(SCHEDULE_URL, params=params)
57
  data = res.json()
58
  try:
59
+ return data["SchoolSchedule"][1]["row"]
 
60
  except:
61
  return []
62
 
63
 
 
64
  def generate_answer(region, school_name, year, month, question):
 
65
  now = datetime.now()
66
  if not year:
67
  year = str(now.year)
 
93
  return result
94
 
95
 
 
96
  with gr.Interface(
97
  fn=generate_answer,
98
  inputs=[
99
  gr.Dropdown(choices=list(REGIONS.keys()), label="ꡐ윑청 선택"),
100
  gr.Textbox(label="학ꡐλͺ… μž…λ ₯"),
101
+ gr.Textbox(label="년도 μž…λ ₯ (예: 2025, λΉ„μ›Œλ‘λ©΄ ν˜„μž¬ 연도 μ‚¬μš©)"),
102
+ gr.Dropdown(choices=MONTH_NAMES, label="μ›” 선택 (예: 07, λΉ„μ›Œλ‘λ©΄ ν˜„μž¬ μ›” μ‚¬μš©)"),
103
  gr.Textbox(label="질문 μž…λ ₯ (예: 여름방학은 μ–Έμ œμ•Ό?)")
104
  ],
105
  outputs=gr.Textbox(label="GPT의 응닡"),
106
+ title="πŸ“… 학사일정 + GPT 챗봇 (Gemma 2B)",
107
+ description="KoAlpaca λŒ€μ‹  Gemma λͺ¨λΈλ‘œ 학사일정 기반 챗봇을 μ‹€ν–‰ν•©λ‹ˆλ‹€."
108
  ) as app:
109
  app.launch()