BillBojangeles2000 commited on
Commit
ad2a25d
·
1 Parent(s): bcb8663

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -38
app.py CHANGED
@@ -100,44 +100,46 @@ for i, question in enumerate(question_list):
100
  questions.append(f"Question: {question}")
101
  scores = []
102
  client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
 
103
  for i in questions:
104
- res = Quiz.text_input(i)
105
- result = client.predict(
106
- f'What would you rate this answer to the question :"{i}" as a percentage? Here is the answer: {res}. Make sure to write your answer as "Score" and then write your score of the response.', # Fixed formatting issue
107
- 0.9,
108
- 256,
109
- 0.9,
110
- 1.2,
111
- api_name="/chat"
112
- )
113
- print(result)
114
- pattern = r'(\d+)%'
115
-
116
- match = re.search(pattern, result)
117
- if match:
118
- score = match.group(1)
119
- scores.append(f'{int(score)}')
120
- else:
121
- scores.append(f'N/A')
122
-
123
- res = Quiz.form_submit_button("Submit")
124
- if res:
125
- x = 0
126
- new_scores = []
127
- for i in scores:
128
- if i == 'N/A':
 
129
  scores.pop(x)
130
  scores.append(85)
131
- x = x+1
132
- else:
133
- x = x+1
134
-
135
- def calculate_average(numbers):
136
- if not numbers:
137
- return 0 # Return 0 for an empty list to avoid division by zero.
138
-
139
- total = sum(numbers)
140
- average = total / len(numbers)
141
- return average
142
-
143
- st.write(f'Your average score is {calculate_average(scores)}')
 
100
  questions.append(f"Question: {question}")
101
  scores = []
102
  client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
103
+ ans = []
104
  for i in questions:
105
+ res = Quiz.text_input(i, key="res")
106
+ ans.append(res)
107
+ for i in ans:
108
+ for q in question:
109
+ result = client.predict(
110
+ 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.',
111
+ 0.9,
112
+ 256,
113
+ 0.9,
114
+ 1.2,
115
+ api_name="/chat"
116
+ )
117
+ print(result)
118
+ pattern = r'(\d+)%'
119
+
120
+ match = re.search(pattern, result)
121
+ if match:
122
+ score = match.group(1)
123
+ scores.append(f'{int(score)}')
124
+ else:
125
+ scores.append(f'N/A')
126
+
127
+ x = 0
128
+ new_scores = []
129
+ for score in scores:
130
+ if score == 'N/A':
131
  scores.pop(x)
132
  scores.append(85)
133
+ x = x + 1
134
+ else:
135
+ x = x + 1
136
+
137
+ def calculate_average(numbers):
138
+ if not numbers:
139
+ return 0 # Return 0 for an empty list to avoid division by zero.
140
+
141
+ total = sum(numbers)
142
+ average = total / len(numbers)
143
+ return average
144
+
145
+ st.write(f'Your average score for the answers is {calculate_average(scores)}')