Spaces:
Runtime error
Runtime error
Commit
·
166fbc5
1
Parent(s):
3d6130b
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import spacy
|
|
7 |
import language_tool_python
|
8 |
import streamlit as st
|
9 |
from gradio_client import Client
|
|
|
10 |
# Initialize LanguageTool
|
11 |
tool = language_tool_python.LanguageToolPublicAPI('en-US')
|
12 |
|
@@ -27,7 +28,7 @@ res = BeautifulSoup(page.content, 'html.parser')
|
|
27 |
|
28 |
text = [i.get_text() for i in res.find_all('p')]
|
29 |
|
30 |
-
cleaned_text = ' '.join
|
31 |
cleaned_text = re.sub(r'[^a-zA-Z0-9.,]', ' ', cleaned_text)
|
32 |
paragraphs = [p.strip() for p in re.split(r'\n', cleaned_text) if p.strip()]
|
33 |
|
@@ -94,32 +95,27 @@ noOfQues = 5
|
|
94 |
subjective_generator = SubjectiveTest(data, noOfQues)
|
95 |
question_list = subjective_generator.generate_test("")
|
96 |
questions = []
|
|
|
97 |
Quiz = st.form("Quiz")
|
98 |
for i, question in enumerate(question_list):
|
99 |
-
|
100 |
-
|
101 |
|
102 |
scores = []
|
103 |
client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
|
104 |
ans = []
|
105 |
-
for i in questions:
|
106 |
-
res = Quiz.text_input(f'{i}')
|
107 |
-
ans.append(res)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
def calculate_average(numbers):
|
112 |
-
if numbers == []:
|
113 |
-
return f'has not been calculated yet.'
|
114 |
-
numbers = [int(x) for x in numbers if isinstance(x, (int, str))]
|
115 |
|
|
|
|
|
|
|
116 |
|
117 |
-
|
118 |
-
average = total / len(numbers)
|
119 |
-
return f'is {average}%'
|
120 |
|
121 |
if submit_button:
|
122 |
-
for i, q in enumerate(questions):
|
123 |
result = client.predict(
|
124 |
f'What would you rate this answer to the question: "{q}" as a percentage? Here is the answer: {ans[i]}. Make sure to write your answer as "Score" and then write your score of the response.',
|
125 |
0.9,
|
@@ -128,23 +124,18 @@ if submit_button:
|
|
128 |
1.2,
|
129 |
api_name="/chat"
|
130 |
)
|
131 |
-
|
132 |
pattern = r'(\d+)%'
|
133 |
|
134 |
match = re.search(pattern, result)
|
135 |
if match:
|
136 |
score = match.group(1)
|
137 |
-
|
138 |
-
else:
|
139 |
-
scores.append(f'N/A')
|
140 |
-
|
141 |
-
x = 0
|
142 |
-
for score in scores:
|
143 |
-
if score == 'N/A':
|
144 |
-
scores.pop(x)
|
145 |
-
scores.append(85)
|
146 |
-
x = x + 1
|
147 |
else:
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
7 |
import language_tool_python
|
8 |
import streamlit as st
|
9 |
from gradio_client import Client
|
10 |
+
|
11 |
# Initialize LanguageTool
|
12 |
tool = language_tool_python.LanguageToolPublicAPI('en-US')
|
13 |
|
|
|
28 |
|
29 |
text = [i.get_text() for i in res.find_all('p')]
|
30 |
|
31 |
+
cleaned_text = ' '.join text)
|
32 |
cleaned_text = re.sub(r'[^a-zA-Z0-9.,]', ' ', cleaned_text)
|
33 |
paragraphs = [p.strip() for p in re.split(r'\n', cleaned_text) if p.strip()]
|
34 |
|
|
|
95 |
subjective_generator = SubjectiveTest(data, noOfQues)
|
96 |
question_list = subjective_generator.generate_test("")
|
97 |
questions = []
|
98 |
+
|
99 |
Quiz = st.form("Quiz")
|
100 |
for i, question in enumerate(question_list):
|
101 |
+
if "Explain" not in question and len(tool.check(question)) == 0 and grammar_sense(question) == "Make Sense":
|
102 |
+
questions.append(f"{question}")
|
103 |
|
104 |
scores = []
|
105 |
client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
|
106 |
ans = []
|
|
|
|
|
|
|
107 |
|
108 |
+
# Create an empty list to store the user-submitted scores
|
109 |
+
user_scores = []
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
for i, question in enumerate(questions):
|
112 |
+
res = Quiz.text_input(f'{question}')
|
113 |
+
ans.append(res)
|
114 |
|
115 |
+
submit_button = Quiz.form_submit_button("Submit")
|
|
|
|
|
116 |
|
117 |
if submit_button:
|
118 |
+
for i, q in enumerate(questions):
|
119 |
result = client.predict(
|
120 |
f'What would you rate this answer to the question: "{q}" as a percentage? Here is the answer: {ans[i]}. Make sure to write your answer as "Score" and then write your score of the response.',
|
121 |
0.9,
|
|
|
124 |
1.2,
|
125 |
api_name="/chat"
|
126 |
)
|
127 |
+
|
128 |
pattern = r'(\d+)%'
|
129 |
|
130 |
match = re.search(pattern, result)
|
131 |
if match:
|
132 |
score = match.group(1)
|
133 |
+
user_scores.append(int(score))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
else:
|
135 |
+
user_scores.append(85) # You can set a default score if no score is found
|
136 |
+
|
137 |
+
# Calculate the average score using the user_scores list
|
138 |
+
average_score = sum(user_scores) / len(user_scores)
|
139 |
+
|
140 |
+
st.subheader(f'Your average score for the answers is {average_score:.2f}%')
|
141 |
+
|