Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,13 @@ import requests
|
|
4 |
from datetime import datetime
|
5 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
6 |
|
7 |
-
#
|
8 |
-
model_id = "
|
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 |
-
#
|
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 |
-
|
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="λ
λ μ
λ ₯ (
|
108 |
-
gr.Dropdown(choices=MONTH_NAMES, label="μ μ ν (
|
109 |
gr.Textbox(label="μ§λ¬Έ μ
λ ₯ (μ: μ¬λ¦λ°©νμ μΈμ μΌ?)")
|
110 |
],
|
111 |
outputs=gr.Textbox(label="GPTμ μλ΅"),
|
112 |
-
title="π
νμ¬μΌμ + GPT μ±λ΄ (
|
113 |
-
description="
|
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()
|