BillBojangeles2000 commited on
Commit
8fbd44d
·
1 Parent(s): d45984f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -45
app.py CHANGED
@@ -123,7 +123,7 @@ class SubjectiveTest:
123
 
124
  questions = []
125
 
126
- for entity_label, entity_questions in question_answer_dict.items():
127
  entity_questions = entity_questions[:self.noOfQues]
128
  questions.extend(entity_questions)
129
 
@@ -136,56 +136,58 @@ with st.form("quiz_form"):
136
 
137
  if generate_quiz:
138
  st.write("Generating the quiz...")
139
- data = ' '.join(paragraphs)
140
  noOfQues = 5
141
 
142
  subjective_generator = SubjectiveTest(data, noOfQues)
143
  questions = subjective_generator.generate_test(topic) # Use the user's input topic here
144
 
145
  # Create a form for the quiz
146
- st.write("Fill out the quiz:")
147
- answers = {}
148
- for i, question in enumerate(questions):
149
- res = st.text_input(f'Q{i + 1}: {question}')
150
- answers[f'Q{i + 1}'] = res
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
- if st.form_submit_button("Submit"):
153
- scores = []
154
- client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
155
 
156
- question_list = subjective_generator.generate_test(topic) # Define 'questions' here
157
- questions = []
158
- for i, question in enumerate(question_list):
159
- if (not "Explain" in question) and (len(tool.check(question)) == 0) and (grammar_sense(question)):
160
- questions.append(f"Question: {question}")
 
 
161
 
162
- for i, question in enumerate(questions):
163
- res = answers[f'Q{i + 1}']
164
- if res:
165
- result = client.predict(
166
- f'What would you rate this answer to the question: "{question}" as a percentage? Here is the answer: {res}. Make sure to write your answer as "Score" and then write your score of the response.',
167
- 0.9,
168
- 256,
169
- 0.9,
170
- 1.2,
171
- api_name="/chat"
172
- )
173
- pattern = r'(\d+)%'
174
- match = re.search(pattern, result)
175
- if match:
176
- score = int(match.group(1))
177
- scores.append(score)
178
- else:
179
- scores.append(85)
180
-
181
- def calculate_average(numbers):
182
- if not numbers:
183
- return 0 # Return 0 for an empty list to avoid division by zero.
184
-
185
- total = sum(numbers)
186
- average = total / len(numbers)
187
- return average
188
-
189
- # Calculate and display the average score
190
- average_score = calculate_average(scores)
191
- st.write(f'Your average score is {average_score}')
 
123
 
124
  questions = []
125
 
126
+ for entity_label, entity_questions in question_answer_dict.items:
127
  entity_questions = entity_questions[:self.noOfQues]
128
  questions.extend(entity_questions)
129
 
 
136
 
137
  if generate_quiz:
138
  st.write("Generating the quiz...")
139
+ data = ' '.join paragraphs
140
  noOfQues = 5
141
 
142
  subjective_generator = SubjectiveTest(data, noOfQues)
143
  questions = subjective_generator.generate_test(topic) # Use the user's input topic here
144
 
145
  # Create a form for the quiz
146
+ with st.form("quiz_submission"):
147
+ st.write("Fill out the quiz:")
148
+ answers = {}
149
+ for i, question in enumerate(questions):
150
+ res = st.text_input(f'Q{i + 1}: {question}')
151
+ answers[f'Q{i + 1}'] = res
152
+
153
+ if st.form_submit_button("Submit"):
154
+ scores = []
155
+ client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
156
+
157
+ question_list = subjective_generator.generate_test(topic) # Define 'questions' here
158
+ questions = []
159
+ for i, question in enumerate(question_list):
160
+ if (not "Explain" in question) and (len(tool.check(question)) == 0) and (grammar_sense(question)):
161
+ questions.append(f"Question: {question}")
162
+
163
+ for i, question in enumerate(questions):
164
+ res = answers[f'Q{i + 1}']
165
+ if res:
166
+ result = client.predict(
167
+ f'What would you rate this answer to the question: "{question}" as a percentage? Here is the answer: {res}. Make sure to write your answer as "Score" and then write your score of the response.',
168
+ 0.9,
169
+ 256,
170
+ 0.9,
171
+ 1.2,
172
+ api_name="/chat"
173
+ )
174
+ pattern = r'(\d+)%'
175
+ match = re.search(pattern, result)
176
+ if match:
177
+ score = int(match.group(1))
178
+ scores.append(score)
179
+ else:
180
+ scores.append(85)
181
 
182
+ def calculate_average(numbers):
183
+ if not numbers:
184
+ return 0 # Return 0 for an empty list to avoid division by zero.
185
 
186
+ total = sum(numbers)
187
+ average = total / len(numbers)
188
+ return average
189
+
190
+ # Calculate and display the average score
191
+ average_score = calculate_average(scores)
192
+ st.write(f'Your average score is {average_score}')
193