Spaces:
Runtime error
Runtime error
merge
Browse files
ice_breaking_challenge/background_task.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
def background_task():
|
2 |
+
"continue"
|
ice_breaking_challenge/introduction.py
CHANGED
@@ -7,18 +7,18 @@ from flask import request
|
|
7 |
from flask import url_for
|
8 |
from werkzeug.exceptions import abort
|
9 |
from flask import session
|
|
|
10 |
|
11 |
from .auth import login_required
|
12 |
from .db import get_db
|
13 |
|
14 |
-
|
15 |
-
bp = Blueprint("introduction", __name__)
|
16 |
|
17 |
|
18 |
@bp.route("/", methods=["GET", "POST"])
|
19 |
-
def
|
20 |
match request.method:
|
21 |
case "GET":
|
22 |
return render_template("introduction.html")
|
23 |
-
case "POST":
|
24 |
-
return
|
|
|
7 |
from flask import url_for
|
8 |
from werkzeug.exceptions import abort
|
9 |
from flask import session
|
10 |
+
from threading import Thread
|
11 |
|
12 |
from .auth import login_required
|
13 |
from .db import get_db
|
14 |
|
15 |
+
bp = Blueprint("introduction", __name__, url_prefix="introduction")
|
|
|
16 |
|
17 |
|
18 |
@bp.route("/", methods=["GET", "POST"])
|
19 |
+
def introduction() -> None:
|
20 |
match request.method:
|
21 |
case "GET":
|
22 |
return render_template("introduction.html")
|
23 |
+
case "POST":
|
24 |
+
return redirect(url_for("topic.topic"))
|
ice_breaking_challenge/models/model_loader.py
CHANGED
@@ -16,47 +16,6 @@ def load_model_with_lora(model_name:str = MODEL_NAME, lora_weight_path: str = LO
|
|
16 |
"""
|
17 |
model = keras_nlp.models.GemmaCausalLM.from_preset(model_name)
|
18 |
|
19 |
-
|
20 |
model.backbone.load_lora_weights(lora_weight_path)
|
21 |
-
# question_crawling="λμ μ΄λ° μ μ μΌν λ λμμ΄ λΌ!?"
|
22 |
-
question_crawling="μ¦κ²¨λ³΄λ μ νλ²?"
|
23 |
-
# answer_crawling="λλκ³ μΆμ΄νλ λ§μ? μ£Όλ³ μ¬λλ€μ κ·Έλ§ νΌμ£ΌλΌκ³ νκΈ°λ νμ§λ§, λ΄κ° ν΄λΌμ΄μΈνΈλ‘λΆν° λμ λ²κ³ μ νλ κ²μ΄ μλλΌ μ‘°κΈμ΄λΌλ λ μ±κ²¨μ£Όκ³ μ νλ λ§μμ κ°μ‘μ λ κ²°κ΅ λμ λΈλλκ° ν¨μ¬ λ μ»€μ§ μ μλ€λ λ―Ώμμ΄ μλ€."
|
24 |
-
answer_crawling="μ λ°, λ립μΉλ κ² μ μ·¨ν₯μ
λλ€."
|
25 |
-
|
26 |
-
input_text = f"""
|
27 |
-
<instruction>
|
28 |
-
Using the text: {question_crawling} {answer_crawling}, create a new multiple-choice question with 4 answer options.
|
29 |
-
"""
|
30 |
-
|
31 |
-
print(model.generate(input_text, max_length=512))
|
32 |
|
33 |
return model
|
34 |
-
|
35 |
-
|
36 |
-
# def template_setting(df:pd.DataFrame, is_test:bool) -> np.ndarray:
|
37 |
-
# template_input="""
|
38 |
-
# <instruction>
|
39 |
-
# Using the text: {question_crawling} {answer_crawling}, create a new multiple-choice question with 4 answer options.
|
40 |
-
# """
|
41 |
-
|
42 |
-
# template_output="""
|
43 |
-
# <Response>
|
44 |
-
# {question_generated}
|
45 |
-
# {multiple_choice_generated}
|
46 |
-
# {answer_generated}
|
47 |
-
# """
|
48 |
-
# template=template_input+'\n'+template_output
|
49 |
-
|
50 |
-
# inputs = np.array(df.apply(lambda row: template.format(
|
51 |
-
# question_crawling=row['question_crawling'],
|
52 |
-
# answer_crawling=row['answer_crawling'],
|
53 |
-
# question_generated=row['question_generated'] if not is_test else "",
|
54 |
-
# multiple_choice_generated=row['multiple_choice_generated'] if not is_test else "",
|
55 |
-
# answer_generated=row['answer_generated'] if not is_test else "").strip(), axis=1))
|
56 |
-
|
57 |
-
# outputs = np.array(df.apply(lambda row: template_output.format(
|
58 |
-
# question_generated=row['question_generated'],
|
59 |
-
# multiple_choice_generated=row['multiple_choice_generated'],
|
60 |
-
# answer_generated=row['answer_generated']).strip(), axis=1))
|
61 |
-
# combined_array = np.column_stack((inputs, outputs))
|
62 |
-
# return combined_array
|
|
|
16 |
"""
|
17 |
model = keras_nlp.models.GemmaCausalLM.from_preset(model_name)
|
18 |
|
|
|
19 |
model.backbone.load_lora_weights(lora_weight_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ice_breaking_challenge/qr.py
CHANGED
@@ -10,10 +10,14 @@ from flask import url_for
|
|
10 |
from werkzeug.exceptions import abort
|
11 |
from flask import session
|
12 |
|
|
|
|
|
13 |
from .auth import login_required
|
14 |
from .db import get_db
|
15 |
from ice_breaking_challenge.google_sheets import get_team_numbers
|
16 |
|
|
|
|
|
17 |
|
18 |
bp = Blueprint("qr", __name__, url_prefix="/qr")
|
19 |
|
@@ -23,12 +27,14 @@ def qr() -> None:
|
|
23 |
match request.method:
|
24 |
case "GET":
|
25 |
return render_template("qr.html")
|
|
|
26 |
case "POST": # qr.htmlμμ `λ€μ` λ²νΌ λλ μ λ
|
27 |
counter = Counter(get_team_numbers())
|
28 |
if session.get("team_number") not in counter:
|
29 |
flash("ν΄λΉ ν λ²νΈκ° μ‘΄μ¬νμ§ μμ΅λλ€.")
|
30 |
return render_template("index.html")
|
31 |
if counter[session.get("team_number")] == session["team_size"]:
|
|
|
32 |
return render_template("introduction.html")
|
33 |
else:
|
34 |
flash("μ€λ¬Έμ μλ£νμ§ μμ νμμ΄ μμ΅λλ€.")
|
|
|
10 |
from werkzeug.exceptions import abort
|
11 |
from flask import session
|
12 |
|
13 |
+
from threading import Thread
|
14 |
+
|
15 |
from .auth import login_required
|
16 |
from .db import get_db
|
17 |
from ice_breaking_challenge.google_sheets import get_team_numbers
|
18 |
|
19 |
+
from background_task import background_task
|
20 |
+
|
21 |
|
22 |
bp = Blueprint("qr", __name__, url_prefix="/qr")
|
23 |
|
|
|
27 |
match request.method:
|
28 |
case "GET":
|
29 |
return render_template("qr.html")
|
30 |
+
|
31 |
case "POST": # qr.htmlμμ `λ€μ` λ²νΌ λλ μ λ
|
32 |
counter = Counter(get_team_numbers())
|
33 |
if session.get("team_number") not in counter:
|
34 |
flash("ν΄λΉ ν λ²νΈκ° μ‘΄μ¬νμ§ μμ΅λλ€.")
|
35 |
return render_template("index.html")
|
36 |
if counter[session.get("team_number")] == session["team_size"]:
|
37 |
+
Thread(target=background_task).start()
|
38 |
return render_template("introduction.html")
|
39 |
else:
|
40 |
flash("μ€λ¬Έμ μλ£νμ§ μμ νμμ΄ μμ΅λλ€.")
|
ice_breaking_challenge/templates/topic.html
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Random Topic Recommendation</title>
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
display: flex;
|
11 |
+
justify-content: center;
|
12 |
+
align-items: center;
|
13 |
+
height: 100vh;
|
14 |
+
font-family: Arial, sans-serif;
|
15 |
+
}
|
16 |
+
h1 {
|
17 |
+
font-size: 2em;
|
18 |
+
color: #333;
|
19 |
+
}
|
20 |
+
</style>
|
21 |
+
</head>
|
22 |
+
<body>
|
23 |
+
<h1 id="topic">μ£Όμ κ° μ¬κΈ°μ νμλ©λλ€</h1>
|
24 |
+
|
25 |
+
<script>
|
26 |
+
// μ£Όμ μ
λ°μ΄νΈ ν¨μ
|
27 |
+
function updateTopic() {
|
28 |
+
fetch('/get_topic')
|
29 |
+
.then(response => response.json())
|
30 |
+
.then(data => {
|
31 |
+
document.getElementById('topic').textContent = data.topic;
|
32 |
+
})
|
33 |
+
.catch(error => console.error('Error fetching topic:', error));
|
34 |
+
}
|
35 |
+
|
36 |
+
// νμ΄μ§κ° λ‘λλ λ μ£Όμ μ
λ°μ΄νΈ
|
37 |
+
updateTopic();
|
38 |
+
|
39 |
+
// 20μ΄λ§λ€ μ£Όμ μ
λ°μ΄νΈ
|
40 |
+
setInterval(updateTopic, 20000);
|
41 |
+
</script>
|
42 |
+
</body>
|
43 |
+
</html>
|
ice_breaking_challenge/topic.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Blueprint, render_template, redirect, url_for
|
2 |
+
import random
|
3 |
+
|
4 |
+
import time
|
5 |
+
|
6 |
+
bp = Blueprint("topic", __name__, url_prefix="topic")
|
7 |
+
topics = ["MBTI", ""]
|
8 |
+
|
9 |
+
@bp.route("/", methods=["GET"])
|
10 |
+
def topic() -> None:
|
11 |
+
if session.get("quiz_generated"):
|
12 |
+
return redirect(url_for("quiz.show_quiz"))
|
13 |
+
else:
|
14 |
+
selected_topic = random.choice(topics)
|
15 |
+
time.sleep(20) # 20μ΄ λκΈ° ν λ€μ μ£Όμ λ‘
|
16 |
+
return render_template("topic.html", topic=selected_topic)
|
17 |
+
|