Ilayda-j commited on
Commit
961f0c2
1 Parent(s): 6a0434a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -25,25 +25,33 @@ def generate_question_and_answer(text):
25
 
26
  return question, answers
27
 
28
- def get_feedback(text=None, user_answer=None, continue_quiz=None):
29
- if text:
30
- question, answers = generate_question_and_answer(text)
31
- return f"Question: {question}\nOptions:\n" + "\n".join(answers)
32
- else:
33
- return "Please input text to generate a question."
 
 
 
 
 
 
34
 
35
  iface = gr.Interface(
36
  fn=get_feedback,
37
  inputs=[
38
  gr.inputs.Textbox(lines=5, label="Input Text"),
39
- gr.inputs.Radio(choices=["1", "2", "3", "4"], label="Your Answer"),
40
- gr.inputs.Radio(choices=["Yes", "No"], label="Continue?")
41
  ],
42
  outputs=[
43
- gr.outputs.Textbox(label="Model Output")
 
44
  ],
45
  live=True
46
  )
47
 
48
  iface.launch()
49
 
 
 
25
 
26
  return question, answers
27
 
28
+ def get_feedback(inputs, state):
29
+ text, user_answer, continue_quiz = inputs
30
+ if state is None:
31
+ state = {'step': 1, 'text': text}
32
+
33
+ if state['step'] == 1:
34
+ if text:
35
+ state['question'], state['answers'] = generate_question_and_answer(text)
36
+ state['step'] = 2
37
+ return {"output": f"Question: {state['question']}\nOptions:\n" + "\n".join(state['answers']), "state": state}
38
+ else:
39
+ return {"output": "Please input text to generate a question.", "state": state}
40
 
41
  iface = gr.Interface(
42
  fn=get_feedback,
43
  inputs=[
44
  gr.inputs.Textbox(lines=5, label="Input Text"),
45
+ gr.inputs.Radio(choices=["1", "2", "3", "4"], label="Your Answer", optional=True),
46
+ gr.inputs.Radio(choices=["Yes", "No"], label="Continue?", optional=True)
47
  ],
48
  outputs=[
49
+ gr.outputs.Textbox(label="Model Output"),
50
+ gr.outputs.State(label="State")
51
  ],
52
  live=True
53
  )
54
 
55
  iface.launch()
56
 
57
+