Spaces:
Runtime error
Runtime error
Commit
·
ad2a25d
1
Parent(s):
bcb8663
Update app.py
Browse files
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 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
129 |
scores.pop(x)
|
130 |
scores.append(85)
|
131 |
-
x = x+1
|
132 |
-
|
133 |
-
x = x+1
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
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)}')
|