rorshi commited on
Commit
a3830f2
·
1 Parent(s): 9625f38

Complete step 1

Browse files
app.py CHANGED
@@ -1,12 +1,15 @@
1
  # portfolio/app.py
2
  from flask import Flask, render_template
3
  from npc_social_network.routes.npc_route import npc_bp
 
 
4
 
5
  def create_app():
6
- app = Flask(__name__)
7
 
8
- # Blueprint 등록
9
- app.register_blueprint(npc_bp)
 
10
 
11
  @app.route("/")
12
  def index():
 
1
  # portfolio/app.py
2
  from flask import Flask, render_template
3
  from npc_social_network.routes.npc_route import npc_bp
4
+ # from stock.routes.stock_route import stock_bp
5
+ import os
6
 
7
  def create_app():
8
+ app = Flask(__name__) # static/template 경로를 기본값
9
 
10
+ # 각 프로젝트는 Blueprint에서 자기 static/template 관리
11
+ app.register_blueprint(npc_bp, url_prefix="/npc")
12
+ # app.register_blueprint(stock_bp, url_prefix="/stock")
13
 
14
  @app.route("/")
15
  def index():
npc_social_network/routes/npc_route.py CHANGED
@@ -1,8 +1,22 @@
1
  # portfolio/npc_social_network/routes/npc_route.py
2
- from flask import Blueprint, render_template
3
 
4
- npc_bp = Blueprint("npc_social", __name__, url_prefix="/npc_social_network", template_folder="../templates")
 
 
 
 
 
5
 
6
  @npc_bp.route("/")
7
- def index():
8
- return render_template("chat.html")
 
 
 
 
 
 
 
 
 
 
1
  # portfolio/npc_social_network/routes/npc_route.py
2
+ from flask import Blueprint, render_template, request, jsonify
3
 
4
+ npc_bp = Blueprint(
5
+ "npc_social",
6
+ __name__,
7
+ url_prefix="/npc_social_network",
8
+ template_folder="../templates",
9
+ static_folder="../static")
10
 
11
  @npc_bp.route("/")
12
+ def home():
13
+ return render_template("chat.html")
14
+
15
+ @npc_bp.route("/chat", methods=['POST'])
16
+ def chat():
17
+ user_input = request.json.get("message")
18
+ npc_name = request.json.get('npc')
19
+
20
+ # 간단한 응답 예시 (GPT 연동 전)
21
+ reply = f"{npc_name}의 대답: '{user_input}'에 대해 생각해볼게."
22
+ return jsonify({'response': reply})
npc_social_network/static/{style.css → css/style.css} RENAMED
File without changes
npc_social_network/static/js/npc_chat.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // portfolio/npc_social_network/static/js/npc_chat.js
2
+
3
+ async function sendMessage() {
4
+ const userMessage = document.getElementById("message").value;
5
+ const npc = document.getElementById("npc").value;
6
+
7
+ const response = await fetch('/chat', {
8
+ method: 'POST',
9
+ headers: { 'Content-Type': 'application/json' },
10
+ body: JSON.stringify({ message: userMessage, npc: npc })
11
+ });
12
+
13
+ const data = await response.json();
14
+ document.getElementById("chatBox").innerHTML += `<p><strong>You:</strong> ${userMessage}</p>`;
15
+ document.getElementById("chatBox").innerHTML += `<p><strong>${npc}:</strong> ${data.response}</p>`;
16
+ }
npc_social_network/templates/base.html CHANGED
@@ -4,9 +4,12 @@
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Document</title>
 
 
8
  </head>
9
  <body>
10
-
 
11
  </body>
12
  </html>
 
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>
8
+ Document
9
+ </title>
10
  </head>
11
  <body>
12
+ <!-- 자바스크립트는 로딩 -->
13
+ <script src="{{ url_for('npc_social.static', filename='js/npc_chat.js') }}"></script>
14
  </body>
15
  </html>
npc_social_network/templates/chat.html CHANGED
@@ -4,9 +4,17 @@
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Document</title>
8
  </head>
9
  <body>
10
-
 
 
 
 
 
 
 
 
11
  </body>
12
  </html>
 
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>NPC Chat</title>
8
  </head>
9
  <body>
10
+ <h1>NPC 소셜 네트워크</h1>
11
+ <select id = "npc">
12
+ <option>Alice</option>
13
+ <option>Bob</option>
14
+ <option>Charlie</option>
15
+ </select>
16
+ <input type="text" id="message" placeholder="메세지를 입력하세요"/>
17
+ <button onclick="sendMessage()">보내기</button>
18
+ <div id="chatBox"></div>
19
  </body>
20
  </html>
templates/main.html CHANGED
@@ -7,6 +7,6 @@
7
  </head>
8
  <body>
9
  <h1>Welcome to the Portfolio</h1>
10
- <a href="/npc_social_network">Go to Project 1</a>
11
  </body>
12
  </html>
 
7
  </head>
8
  <body>
9
  <h1>Welcome to the Portfolio</h1>
10
+ <a href="{{ url_for('npc_social.home') }}">Go to Project 1</a>
11
  </body>
12
  </html>
test.ipynb CHANGED
@@ -1,8 +1,37 @@
1
  {
2
- "cells": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  "metadata": {
 
 
 
 
 
4
  "language_info": {
5
- "name": "python"
 
6
  }
7
  },
8
  "nbformat": 4,
 
1
  {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "ecf4c973",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "# 설치된 라이브러리 txt로 추출하기\n",
11
+ "!pip freeze > requirements.txt"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": null,
17
+ "id": "b58bbb07",
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": [
21
+ "# txt 라이브러리 설치하기\n",
22
+ "!pip install -r requirements.txt"
23
+ ]
24
+ }
25
+ ],
26
  "metadata": {
27
+ "kernelspec": {
28
+ "display_name": "portfolio",
29
+ "language": "python",
30
+ "name": "python3"
31
+ },
32
  "language_info": {
33
+ "name": "python",
34
+ "version": "3.11.11"
35
  }
36
  },
37
  "nbformat": 4,