BillBojangeles2000 commited on
Commit
104329a
·
1 Parent(s): 09d4026

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -38
app.py CHANGED
@@ -107,42 +107,44 @@ for i in questions:
107
  ans.append(res)
108
 
109
  Quiz.form_submit_button("Submit")
110
- for i in ans:
111
- for q in question:
112
- result = client.predict(
113
- f'What would you rate this answer to the question: "{q}" as a percentage? Here is the answer: {i}. Make sure to write your answer as "Score" and then write your score of the response.',
114
- 0.9,
115
- 256,
116
- 0.9,
117
- 1.2,
118
- api_name="/chat"
119
- )
120
- print(result)
121
- pattern = r'(\d+)%'
122
-
123
- match = re.search(pattern, result)
124
- if match:
125
- score = match.group(1)
126
- scores.append(f'{int(score)}')
 
 
 
 
 
 
 
 
 
 
 
 
127
  else:
128
- scores.append(f'N/A')
129
-
130
- x = 0
131
- new_scores = []
132
- for score in scores:
133
- if score == 'N/A':
134
- scores.pop(x)
135
- scores.append(85)
136
- x = x + 1
137
- else:
138
- x = x + 1
139
-
140
- def calculate_average(numbers):
141
- if not numbers:
142
- return 0 # Return 0 for an empty list to avoid division by zero.
143
-
144
- total = sum(numbers)
145
- average = total / len(numbers)
146
- return average
147
-
148
- st.write(f'Your average score for the answers is {calculate_average(scores)}')
 
107
  ans.append(res)
108
 
109
  Quiz.form_submit_button("Submit")
110
+ grade_quiz = st.button("Grade Quiz!")
111
+ if grade_quiz:
112
+ for i in ans:
113
+ for q in question:
114
+ result = client.predict(
115
+ f'What would you rate this answer to the question: "{q}" as a percentage? Here is the answer: {i}. Make sure to write your answer as "Score" and then write your score of the response.',
116
+ 0.9,
117
+ 256,
118
+ 0.9,
119
+ 1.2,
120
+ api_name="/chat"
121
+ )
122
+ print(result)
123
+ pattern = r'(\d+)%'
124
+
125
+ match = re.search(pattern, result)
126
+ if match:
127
+ score = match.group(1)
128
+ scores.append(f'{int(score)}')
129
+ else:
130
+ scores.append(f'N/A')
131
+
132
+ x = 0
133
+ new_scores = []
134
+ for score in scores:
135
+ if score == 'N/A':
136
+ scores.pop(x)
137
+ scores.append(85)
138
+ x = x + 1
139
  else:
140
+ x = x + 1
141
+
142
+ def calculate_average(numbers):
143
+ if not numbers:
144
+ return 0 # Return 0 for an empty list to avoid division by zero.
145
+
146
+ total = sum(numbers)
147
+ average = total / len(numbers)
148
+ return average
149
+
150
+ st.subheader(f'Your average score for the answers is {calculate_average(scores)}')