jpruzcuen commited on
Commit
f95926d
·
1 Parent(s): 6e8eb29

retro fix

Browse files
Files changed (1) hide show
  1. app.py +82 -65
app.py CHANGED
@@ -1,87 +1,104 @@
1
  import gradio as gr
2
- from quiz import start_quiz, answer_question, format_question, parse_quiz, create_quiz
 
3
  from llama_cpp import Llama
4
  from huggingface_hub import hf_hub_download
5
  from functools import partial
6
 
7
- # Load model
8
  model_path = hf_hub_download(
9
  repo_id="ebbalg/llama-finetome",
10
  filename="llama-3.2-1b-instruct.Q4_K_M.gguf"
11
  )
12
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2, verbose=False, chat_format="llama-3")
13
 
14
- # Generate and parse quiz
15
- raw_quiz = create_quiz(llm)
16
- parsed_quiz = parse_quiz(raw_quiz)
17
-
18
  with gr.Blocks(title="TAI: AI Teacher Assistant") as demo:
19
- gr.Markdown("# TAI: Your AI Teacher Assistant\nTest your ML knowledge with a quiz!")
20
-
21
- start_btn = gr.Button("Start Quiz", variant="primary")
22
- question_md = gr.Markdown("")
23
- feedback_md = gr.Markdown("")
24
- progress_md = gr.Markdown("")
25
 
26
- # Answer buttons
27
  with gr.Row():
28
- btn_A = gr.Button("A", visible=False)
29
- btn_B = gr.Button("B", visible=False)
30
- btn_C = gr.Button("C", visible=False)
31
- btn_D = gr.Button("D", visible=False)
32
- retry_btn = gr.Button("Retry", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- # States
35
- idx_state = gr.State(0)
36
- score_state = gr.State(0)
37
 
38
- # Start quiz
39
- def start_quiz_ui():
40
- q_text, feedback, progress, idx, score = start_quiz(parsed_quiz)
41
- return (
42
- q_text, feedback, progress, idx, score,
43
- gr.update(visible=False), # hide start
44
- gr.update(visible=True), # show buttons
45
- gr.update(visible=True),
46
- gr.update(visible=True),
47
- gr.update(visible=True),
48
- gr.update(visible=True) # show retry
49
- )
50
 
51
- start_btn.click(
52
- fn=start_quiz_ui,
53
- inputs=[],
54
- outputs=[question_md, feedback_md, progress_md, idx_state, score_state,
55
- start_btn, btn_A, btn_B, btn_C, btn_D, retry_btn]
56
- )
57
 
58
- # Answer buttons
59
- for letter, btn in zip(["A", "B", "C", "D"], [btn_A, btn_B, btn_C, btn_D]):
60
- btn_fn = partial(answer_question, parsed_quiz, letter)
61
- btn.click(
62
- fn=btn_fn,
63
- inputs=[idx_state, score_state],
64
- outputs=[question_md, idx_state, score_state, feedback_md, progress_md]
65
- )
66
 
67
- # Retry
68
- def retry_quiz_ui():
69
- q_text, feedback, progress, idx, score = start_quiz(parsed_quiz)
70
- return (
71
- q_text, feedback, progress, idx, score,
72
- gr.update(visible=True), # show start
73
- gr.update(visible=False), # hide buttons
74
- gr.update(visible=False),
75
- gr.update(visible=False),
76
- gr.update(visible=False),
77
- gr.update(visible=False) # hide retry
78
- )
79
 
80
- retry_btn.click(
81
- fn=retry_quiz_ui,
82
- inputs=[],
83
- outputs=[question_md, feedback_md, progress_md, idx_state, score_state,
84
- start_btn, btn_A, btn_B, btn_C, btn_D, retry_btn]
85
- )
86
 
87
  demo.launch()
 
1
  import gradio as gr
2
+ from quiz import start_quiz, answer_question, parsed_quiz, format_question
3
+ from chatbot import chat
4
  from llama_cpp import Llama
5
  from huggingface_hub import hf_hub_download
6
  from functools import partial
7
 
8
+ # Load model (unchanged)
9
  model_path = hf_hub_download(
10
  repo_id="ebbalg/llama-finetome",
11
  filename="llama-3.2-1b-instruct.Q4_K_M.gguf"
12
  )
13
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2, verbose=False, chat_format="llama-3")
14
 
 
 
 
 
15
  with gr.Blocks(title="TAI: AI Teacher Assistant") as demo:
16
+ gr.Markdown("""
17
+ # TAI: Your AI Teacher Assistant
18
+ Ask questions about AI and Machine Learning! Test your understanding with a quiz.
19
+ """)
 
 
20
 
 
21
  with gr.Row():
22
+ # Chat column
23
+ with gr.Column(scale=1):
24
+ gr.Markdown("## Ask me anything")
25
+ gr.ChatInterface(
26
+ fn=lambda message, history: chat(llm, message, history),
27
+ examples=[
28
+ "Which tasks can recurrent neural networks address?",
29
+ "Explain backpropagation in simple terms.",
30
+ "What are the benefits of regularization during training?",
31
+ "Write a short summary of advancements that allowed for deep neural networks to work."
32
+ ]
33
+ )
34
+
35
+ # Quiz column
36
+ with gr.Column(scale=2):
37
+ gr.Markdown("## Test Yourself")
38
+ start_btn = gr.Button("Start Quiz", variant="primary")
39
+ question_md = gr.Markdown("")
40
+ feedback_md = gr.Markdown("")
41
+ progress_md = gr.Markdown("")
42
+
43
+ # Answer buttons
44
+ with gr.Row():
45
+ btn_A = gr.Button("A", visible=False)
46
+ btn_B = gr.Button("B", visible=False)
47
+ btn_C = gr.Button("C", visible=False)
48
+ btn_D = gr.Button("D", visible=False)
49
+ retry_btn = gr.Button("Retry", visible=False)
50
 
51
+ # States
52
+ idx_state = gr.State(0)
53
+ score_state = gr.State(0)
54
 
55
+ # Start quiz
56
+ def start_quiz_ui():
57
+ q_text, feedback, progress, idx, score = start_quiz(parsed_quiz)
58
+ return (
59
+ q_text, feedback, progress, idx, score,
60
+ gr.update(visible=False), # hide start
61
+ gr.update(visible=True), # show A
62
+ gr.update(visible=True), # show B
63
+ gr.update(visible=True), # show C
64
+ gr.update(visible=True), # show D
65
+ gr.update(visible=True) # show retry
66
+ )
67
 
68
+ start_btn.click(
69
+ fn=start_quiz_ui,
70
+ inputs=[],
71
+ outputs=[question_md, feedback_md, progress_md, idx_state, score_state,
72
+ start_btn, btn_A, btn_B, btn_C, btn_D, retry_btn]
73
+ )
74
 
75
+ # Answer button clicks
76
+ for letter, btn in zip(["A", "B", "C", "D"], [btn_A, btn_B, btn_C, btn_D]):
77
+ btn_fn = partial(answer_question, parsed_quiz, letter)
78
+ btn.click(
79
+ fn=btn_fn,
80
+ inputs=[idx_state, score_state],
81
+ outputs=[question_md, idx_state, score_state, feedback_md, progress_md]
82
+ )
83
 
84
+ # Retry button
85
+ def retry_quiz_ui():
86
+ q_text, feedback, progress, idx, score = start_quiz(parsed_quiz)
87
+ return (
88
+ q_text, feedback, progress, idx, score,
89
+ gr.update(visible=True), # show start
90
+ gr.update(visible=False), # hide A
91
+ gr.update(visible=False), # hide B
92
+ gr.update(visible=False), # hide C
93
+ gr.update(visible=False), # hide D
94
+ gr.update(visible=False) # hide retry
95
+ )
96
 
97
+ retry_btn.click(
98
+ fn=retry_quiz_ui,
99
+ inputs=[],
100
+ outputs=[question_md, feedback_md, progress_md, idx_state, score_state,
101
+ start_btn, btn_A, btn_B, btn_C, btn_D, retry_btn]
102
+ )
103
 
104
  demo.launch()