Spaces:
Runtime error
Runtime error
Commit
·
987bab3
1
Parent(s):
8c0f868
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,10 @@ st.title("NLP Testing and Scoring App")
|
|
59 |
topic = st.text_input("Enter a topic (optional):")
|
60 |
|
61 |
# Web scraping and text cleaning
|
62 |
-
entity = "Florida"
|
|
|
|
|
|
|
63 |
prefix = "https://wiki.kidzsearch.com/wiki/"
|
64 |
page = requests.get(f'{prefix}{entity}')
|
65 |
res = BeautifulSoup(page.content, 'html.parser')
|
@@ -126,57 +129,61 @@ class SubjectiveTest:
|
|
126 |
|
127 |
return questions
|
128 |
|
129 |
-
#
|
130 |
-
|
131 |
-
noOfQues = 5
|
132 |
|
133 |
-
|
134 |
-
|
|
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
answers = {}
|
139 |
-
for i, question in enumerate(questions):
|
140 |
-
res = st.text_input(f'Q{i + 1}: {question}')
|
141 |
-
answers[f'Q{i + 1}'] = res
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
if "Explain" not in question and len(tool.check(question)) == 0 and grammar_sense(question):
|
151 |
-
questions.append(f"Question: {question}")
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
f
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
topic = st.text_input("Enter a topic (optional):")
|
60 |
|
61 |
# Web scraping and text cleaning
|
62 |
+
entity = "Florida" # You can replace this with the user's topic input
|
63 |
+
if topic:
|
64 |
+
entity = topic # Use the user's input as the entity
|
65 |
+
|
66 |
prefix = "https://wiki.kidzsearch.com/wiki/"
|
67 |
page = requests.get(f'{prefix}{entity}')
|
68 |
res = BeautifulSoup(page.content, 'html.parser')
|
|
|
129 |
|
130 |
return questions
|
131 |
|
132 |
+
# Create a button to initiate quiz generation
|
133 |
+
generate_quiz = st.button("Generate Quiz")
|
|
|
134 |
|
135 |
+
if generate_quiz:
|
136 |
+
st.write("Generating the quiz...")
|
137 |
+
data = ' '.join(paragraphs)
|
138 |
+
noOfQues = 5
|
139 |
|
140 |
+
subjective_generator = SubjectiveTest(data, noOfQues)
|
141 |
+
questions = subjective_generator.generate_test(topic) # Use the user's input topic here
|
|
|
|
|
|
|
|
|
142 |
|
143 |
+
# Create a form for the quiz
|
144 |
+
st.write("Fill out the quiz:")
|
145 |
+
answers = {}
|
146 |
+
for i, question in enumerate(questions):
|
147 |
+
res = st.text_input(f'Q{i + 1}: {question}')
|
148 |
+
answers[f'Q{i + 1}'] = res
|
149 |
|
150 |
+
if st.button("Submit"):
|
151 |
+
scores = []
|
152 |
+
client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
|
|
|
|
|
153 |
|
154 |
+
question_list = subjective_generator.generate_test(topic) # Define 'questions' here
|
155 |
+
questions = []
|
156 |
+
for i, question in enumerate(question_list):
|
157 |
+
if "Explain" not in question and len(tool.check(question)) == 0 and grammar_sense(question):
|
158 |
+
questions.append(f"Question: {question}")
|
159 |
+
|
160 |
+
for i, question in enumerate(questions):
|
161 |
+
res = answers[f'Q{i + 1}']
|
162 |
+
if res:
|
163 |
+
result = client.predict(
|
164 |
+
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.',
|
165 |
+
0.9,
|
166 |
+
256,
|
167 |
+
0.9,
|
168 |
+
1.2,
|
169 |
+
api_name="/chat"
|
170 |
+
)
|
171 |
+
pattern = r'(\d+)%'
|
172 |
+
match = re.search(pattern, result)
|
173 |
+
if match:
|
174 |
+
score = int(match.group(1))
|
175 |
+
scores.append(score)
|
176 |
+
else:
|
177 |
+
scores.append(85)
|
178 |
+
|
179 |
+
def calculate_average(numbers):
|
180 |
+
if not numbers:
|
181 |
+
return 0 # Return 0 for an empty list to avoid division by zero.
|
182 |
+
|
183 |
+
total = sum(numbers)
|
184 |
+
average = total / len(numbers)
|
185 |
+
return average
|
186 |
+
|
187 |
+
# Calculate and display the average score
|
188 |
+
average_score = calculate_average(scores)
|
189 |
+
st.write(f'Your average score is {average_score}')
|