Skip to content

Project Introduction

SeungWon Lee edited this page May 14, 2024 · 1 revision

프로젝트 Wiki 페이지 [KOR]

프로젝트 개요

이 프로젝트는 Flask 웹 애플리케이션으로, 다양한 웹사이트에서 데이터를 크롤링하고, 크롤링한 데이터를 기반으로 질문에 대한 답변을 제공하는 시스템입니다. 주요 기능은 다음과 같습니다:

  • 웹사이트 공지사항 크롤링
  • 학사 일정 크롤링
  • 도서관 좌석 정보 크롤링
  • 학식 메뉴 크롤링
  • 질문에 대한 최적의 답변 제공

Installation 환경

요구 사항

  • Python 3.7 이상
  • pip (Python 패키지 관리자)

설치 방법

  1. 프로젝트를 클론합니다:

    git clone https://github.com/your-repo/your-project.git
    cd your-project
  2. 필요한 라이브러리를 설치합니다:

    pip install -r requirements.txt
  3. dataset 폴더를 생성하고 필요한 JSON 파일을 저장할 수 있는 경로를 확인합니다.

  4. Flask 애플리케이션을 실행합니다:

    python app.py

Library

주요 라이브러리

  • Flask: 웹 애플리케이션 프레임워크로 사용됩니다.
  • apscheduler: 정기적으로 작업을 예약하고 실행하는 데 사용됩니다.
  • flasgger: Swagger UI를 통해 API 문서를 자동으로 생성하고 제공합니다.
  • json: 데이터를 JSON 형식으로 저장하고 로드하는 데 사용됩니다.

추가 라이브러리

  • question_processing: 질문을 처리하고 가장 적합한 답변을 선택하는 모듈입니다.
  • crawler: 다양한 웹사이트에서 데이터를 크롤링하는 모듈입니다.
  • httpx: HTTP 클라이언트로, 웹 페이지로부터 데이터를 가져오는 데 사용됩니다.
  • BeautifulSoup: HTML 파싱 라이브러리로, 웹 페이지로부터 원하는 데이터를 추출하는 데 사용됩니다.
  • torch, sentence_transformers: 질문을 임베딩하고 유사한 질문을 찾는 데 사용됩니다.
  • pandas: 데이터 프레임을 처리하는 데 사용됩니다.
  • numpy: 수치 데이터를 처리하는 데 사용됩니다.

API에 대한 구체적인 설명

GET /get-question/

질문에 대한 최적의 답변을 반환합니다.

  • URL: /get-question/<question>
  • Method: GET
  • URL 파라미터:
    • question (string): 사용자의 질문
  • 응답:
    • answer (string): 질문에 대한 최적의 답변
    • button_name (string): 버튼 이름
    • link (string): 관련 링크
    • question (string): 처리된 질문

예제 요청

curl -X GET "http://localhost:5000/get-question/도서관 좌석은?"

예제 응답

{
  "answer": "현재 도서관 좌석 정보는 ...",
  "button_name": "도서관 좌석 확인",
  "link": "http://library.example.com/seats",
  "question": "도서관 좌석은?"
}

예제코드

예제 1: 질문에 대한 답변 요청

아래 코드는 Flask 애플리케이션을 실행하고 /get-question 엔드포인트에 GET 요청을 보내 질문에 대한 답변을 받는 예제입니다.

import requests

def get_answer(question):
    url = f"http://localhost:5000/get-question/{question}"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        print(f"Question: {data['question']}")
        print(f"Answer: {data['answer']}")
        print(f"Link: {data['link']}")
        print(f"Button Name: {data['button_name']}")
    else:
        print("Error:", response.status_code)

if __name__ == "__main__":
    question = "도서관 좌석은?"
    get_answer(question)

이 코드는 로컬 서버에서 Flask 애플리케이션을 실행한 후, 사용자가 입력한 질문에 대해 가장 적합한 답변을 반환합니다. 응답 데이터는 JSON 형식으로 반환되며, 각 키와 값을 출력합니다.

Project Wiki Page [ENG]

Project Overview

This project is a Flask web application that crawls data from various websites and provides answers to questions based on the crawled data. The main features include:

  • Crawling website notices
  • Crawling academic schedules
  • Crawling library seat information
  • Crawling cafeteria menus
  • Providing the best answers to questions

Installation Environment

Requirements

  • Python 3.7 or higher
  • pip (Python package manager)

Installation Steps

  1. Clone the project:

    git clone https://github.com/your-repo/your-project.git
    cd your-project
  2. Install the required libraries:

    pip install -r requirements.txt
  3. Create the dataset folder and ensure the necessary JSON files can be stored in it.

  4. Run the Flask application:

    python app.py

Libraries

Main Libraries

  • Flask: Used as the web application framework.
  • apscheduler: Used to schedule and execute tasks regularly.
  • flasgger: Provides automatic generation and display of API documentation via Swagger UI.
  • json: Used to save and load data in JSON format.

Additional Libraries

  • question_processing: Module for processing questions and selecting the best answer.
  • crawler: Module for crawling data from various websites.
  • httpx: HTTP client used for fetching data from web pages.
  • BeautifulSoup: HTML parsing library used for extracting desired data from web pages.
  • torch, sentence_transformers: Used for embedding questions and finding similar questions.
  • pandas: Used for handling data frames.
  • numpy: Used for numerical data processing.

Detailed API Explanation

GET /get-question/

Returns the best answer for the given question.

  • URL: /get-question/<question>
  • Method: GET
  • URL Parameters:
    • question (string): The user's question
  • Response:
    • answer (string): The best answer to the question
    • button_name (string): The button name
    • link (string): The relevant link
    • question (string): The processed question

Example Request

curl -X GET "http://localhost:5000/get-question/What is the availability of library seats?"

Example Response

{
  "answer": "The current library seat information is ...",
  "button_name": "Check Library Seats",
  "link": "http://library.example.com/seats",
  "question": "What is the availability of library seats?"
}

Example Code

Example 1: Requesting an Answer to a Question

The code below runs the Flask application and sends a GET request to the /get-question endpoint to get an answer to a question.

import requests

def get_answer(question):
    url = f"http://localhost:5000/get-question/{question}"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        print(f"Question: {data['question']}")
        print(f"Answer: {data['answer']}")
        print(f"Link: {data['link']}")
        print(f"Button Name: {data['button_name']}")
    else:
        print("Error:", response.status_code)

if __name__ == "__main__":
    question = "What is the availability of library seats?"
    get_answer(question)

This code runs the Flask application on the local server and returns the most suitable answer to the user's question. The response data is returned in JSON format, and each key and value is printed out.