KunalThakare279 commited on
Commit
20cde61
·
verified ·
1 Parent(s): 3b9f761

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -23
app.py CHANGED
@@ -1,29 +1,58 @@
1
- from flask import Flask, render_template, request
 
2
  from llm import get_prompt, get_responce
3
 
4
- app = Flask(__name__)
5
-
6
- # Assume your question generation logic is already defined
7
  def generate_questions(question_type):
8
- if question_type == 'mcq':
9
- return ["What is the capital of France?", "Choose the correct answer from four options."]
10
- elif question_type == 'fill_blank':
11
- return ["The sun rises in the ____.", "Fill in the correct word."]
12
- elif question_type == 'short_answer':
13
- return ["Explain the process of photosynthesis."]
14
- else:
15
- return ["No questions available for the selected type."]
16
-
17
- @app.route('/')
18
- def home():
19
- return render_template('index.html')
20
-
21
- @app.route('/get_questions', methods=['POST'])
22
- def get_questions():
23
- question_type = request.form['question_type']
24
  prompt, seed = get_prompt(question_type)
25
  questions = get_responce(prompt)
26
- return render_template('questions.html', questions=questions, question_type=questions[0]["question_type"], seed = seed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- if __name__ == '__main__':
29
- app.run(debug=True)
 
1
+ import gradio as gr
2
+ import random
3
  from llm import get_prompt, get_responce
4
 
 
 
 
5
  def generate_questions(question_type):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  prompt, seed = get_prompt(question_type)
7
  questions = get_responce(prompt)
8
+ return questions, seed
9
+
10
+ def process_question_type(question_type):
11
+ questions, seed = generate_questions(question_type)
12
+ formatted_questions = []
13
+
14
+ for question in questions:
15
+ question_text = question["question"]
16
+ options = question.get("options", {})
17
+ answer = question["answer"]
18
+ correction = question.get("correction", "")
19
+
20
+ question_display = {
21
+ "Question": question_text,
22
+ "Answer": answer,
23
+ "Correction": correction,
24
+ "Options": options if options else None,
25
+ }
26
+ formatted_questions.append(question_display)
27
+
28
+ return formatted_questions, seed
29
+
30
+ def main():
31
+ question_types = [
32
+ "Choose the correct meaning of the word",
33
+ "Personal response",
34
+ "Give reasons",
35
+ "Fill in the blanks",
36
+ "True or False",
37
+ ]
38
+
39
+ # Create a Gradio interface
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("<h1>Select Question Type</h1>")
42
+ question_type = gr.Dropdown(choices=question_types, label="Question Type", value=question_types[0])
43
+ generate_button = gr.Button("Generate Questions")
44
+
45
+ output = gr.Textbox(label="Generated Questions", interactive=False)
46
+ seed_output = gr.Textbox(label="Seed Number", interactive=False)
47
+
48
+ def generate():
49
+ questions, seed = process_question_type(question_type.value)
50
+ formatted_output = "\n".join([f"{q['Question']} - Answer: {q['Answer']}, Correction: {q['Correction']}" for q in questions])
51
+ return formatted_output, seed
52
+
53
+ generate_button.click(generate, outputs=[output, seed_output])
54
+
55
+ demo.launch()
56
 
57
+ if __name__ == "__main__":
58
+ main()