KIM2683 commited on
Commit
e89e5a8
·
verified ·
1 Parent(s): 254864a

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +18 -5
  2. app.py +41 -60
  3. requirements.txt +8 -1
README.md CHANGED
@@ -1,12 +1,25 @@
1
  ---
2
- title: Cur
3
- emoji: 💬
4
- colorFrom: yellow
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.0.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: 진로별 전공·과목 추천 챗봇
3
+ emoji: 🎓
4
+ colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.0.2
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
+ # 진로별 전공·과목 추천 PDF 연계 챗봇
14
+
15
+ 희망하는 진로를 입력하면 해당 진로에 맞는 추천 전공과 과목을 알려주고,
16
+ 관련 교육과정 편성표 PDF에서 일부 페이지를 이미지로 함께 보여줍니다.
17
+
18
+ ## 사용 방법
19
+ 1. 희망 진로명을 텍스트 박스에 입력하세요 (예: 의학전문사서)
20
+ 2. '답변 받기' 버튼을 클릭하면 추천 전공과 과목, 그리고 관련 PDF 이미지가 출력됩니다.
21
+
22
+ ## 주요 기능
23
+ - 진로별 추천 전공과 수강 과목 안내
24
+ - 교육과정 편성표 PDF 일부 페이지 이미지 자동 추출 및 표시
25
+ - 직관적인 UI로 빠른 정보 확인 가능
app.py CHANGED
@@ -1,64 +1,45 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
 
 
 
 
 
 
 
 
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ import fitz
3
+ import gradio as gr
4
+ import os
5
+
6
+ PDF_PATH = "/content/drive/MyDrive/Colab Notebooks/교육과정 편성표.pdf"
7
+
8
+ career_to_courses = {'의학전문사서': {'전공': ['간호학과', '문헌정보학과'], '추천과목': ['해부학', '정보분류론', '문헌정보학개론', '임상실습']}, '데이터 사이언티스트': {'전공': ['컴퓨터공학과', '빅데이터응용학과'], '추천과목': ['빅데이터의이해', 'phython기초', '빅데이터분석']}, '인공지능 연구원': {'전공': ['컴퓨터공학과', '전자공학과'], '추천과목': ['인공지능기초', '딥러닝', '컴퓨터비전']}, '소프트웨어 개발자': {'전공': ['컴퓨터공학과', '기계공학과'], '추천과목': ['자료구조', '운영체제', '웹프로그래밍']}, '경영 컨설턴트': {'전공': ['경영학과', '경제학과'], '추천과목': ['회계원리', '마케팅', '경영전략']}, '환경공학자': {'전공': ['환경공학과', '화학공학과'], '추천과목': ['환경오염학', '수질관리', '대기환경학']}, '건축전문사서': {'전공': ['건축학과', '문헌정보학과'], '추천과목': ['건축설계', '문헌정보학개론', '재료학']}, '심리상담사': {'전공': ['심리학과', '사회복지학과'], '추천과목': ['상담심리학', '발달심리학', '사회복지개론']}, '지식재산 전문가': {'전공': ['법학과', '경제학과'], '추천과목': ['지식재산법', '상표법', '특허정보분석']}, '아동 콘텐츠 기획자': {'전공': ['아동복지학과', '미디어학과'], '추천과목': ['아동발달', '콘텐츠기획', '미디어제작']}}
9
+ career_to_pdf_pages = {'의학전문사서': [354, 57], '데이터 사이언티스트': [378, 397], '인공지능 연구원': [378, 111], '소프트웨어 개발자': [378, 142], '경영 컨설턴트': [173, 202], '환경공학자': [334, 335, 155], '건축전문사서': [57, 124], '심리상담사': [258, 268], '지식재산 전문가': [225, 202], '아동 콘텐츠 기획자': [266, 307]}
10
+
11
+ def recommend_courses_with_pdf(user_input):
12
+ user_input_lower = user_input.lower()
13
+ for career, info in career_to_courses.items():
14
+ if career.lower() in user_input_lower:
15
+ majors = ", ".join(info["전공"])
16
+ courses = ", ".join(info["추천과목"])
17
+ text = f"'{career}'가 되고 싶다면 추천 전공은 [{majors}]이고, 수강하면 좋은 과목은 [{courses}]입니다."
18
+
19
+ pages = career_to_pdf_pages.get(career, [])
20
+ images = []
21
+
22
+ if pages and os.path.exists(PDF_PATH):
23
+ doc = fitz.open(PDF_PATH)
24
+ for p in pages:
25
+ page = doc.load_page(p - 1)
26
+ pix = page.get_pixmap(dpi=150)
27
+ img_path = f"/tmp/{career}_page{p}.png"
28
+ pix.save(img_path)
29
+ images.append(img_path)
30
+ doc.close()
31
+
32
+ return text, images if images else None
33
+
34
+ return "해당 진로에 대한 정보가 없습니다. 다른 진로명을 입력해 주세요.", None
35
+
36
+ iface = gr.Interface(
37
+ fn=recommend_courses_with_pdf,
38
+ inputs=gr.Textbox(lines=2, placeholder="희망 진로를 입력하세요 (예: 의학전문사서)"),
39
+ outputs=[gr.Textbox(label="추천 전공 및 과목"), gr.Gallery(label="관련 PDF 페이지 이미지")],
40
+ title="진로별 전공·과목 추천 및 PDF 연계 챗봇",
41
+ description="진로명을 입력하면 관련 전공, 과목과 함께 PDF 일부 페이지를 이미지로 보여줍니다."
42
  )
43
 
 
44
  if __name__ == "__main__":
45
+ iface.launch()
requirements.txt CHANGED
@@ -1 +1,8 @@
1
- huggingface_hub==0.25.2
 
 
 
 
 
 
 
 
1
+ gradio==4.0.2
2
+ langchain==0.1.0
3
+ langchain-groq==0.1.0
4
+ faiss-cpu==1.7.4
5
+ sentence-transformers==2.2.2
6
+ python-dotenv==1.0.0
7
+ pypdf==3.17.0
8
+ tiktoken==0.5.1