Spaces:
Runtime error
Runtime error
Commit
·
9ca337b
1
Parent(s):
9750c43
Update app.py
Browse files
app.py
CHANGED
@@ -54,8 +54,12 @@ tool = language_tool_python.LanguageToolPublicAPI('en-US')
|
|
54 |
|
55 |
# Define the Streamlit app
|
56 |
st.title("NLP Testing and Scoring App")
|
|
|
|
|
|
|
|
|
57 |
# Web scraping and text cleaning
|
58 |
-
entity = "
|
59 |
prefix = "https://wiki.kidzsearch.com/wiki/"
|
60 |
page = requests.get(f'{prefix}{entity}')
|
61 |
res = BeautifulSoup(page.content, 'html.parser')
|
@@ -128,49 +132,44 @@ noOfQues = 5
|
|
128 |
|
129 |
subjective_generator = SubjectiveTest(data, noOfQues)
|
130 |
|
131 |
-
#
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
# Add a Streamlit UI for input and displaying scores
|
136 |
-
question_list = subjective_generator.generate_test(topic)
|
137 |
-
questions = []
|
138 |
-
for i, question in enumerate(question_list):
|
139 |
-
if "Explain" not in question and len(tool.check(question)) == 0 and grammar_sense(question):
|
140 |
-
questions.append(f"Question: {question}")
|
141 |
-
|
142 |
-
# Display the generated questions
|
143 |
-
st.write("Generated Questions:")
|
144 |
-
for q in questions:
|
145 |
-
st.write(q)
|
146 |
-
|
147 |
for i, question in enumerate(questions):
|
148 |
-
res = st.text_input(f'{
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Define the Streamlit app
|
56 |
st.title("NLP Testing and Scoring App")
|
57 |
+
|
58 |
+
# Ask for the topic at the start
|
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')
|
|
|
132 |
|
133 |
subjective_generator = SubjectiveTest(data, noOfQues)
|
134 |
|
135 |
+
# Create a form for the quiz
|
136 |
+
st.write("Fill out the quiz:")
|
137 |
+
answers = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
for i, question in enumerate(questions):
|
139 |
+
res = st.text_input(f'Q{i + 1}: {question}')
|
140 |
+
answers[f'Q{i + 1}'] = res
|
141 |
+
|
142 |
+
if st.button("Submit"):
|
143 |
+
scores = []
|
144 |
+
client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
|
145 |
+
|
146 |
+
for i, question in enumerate(questions):
|
147 |
+
res = answers[f'Q{i + 1}']
|
148 |
+
if res:
|
149 |
+
result = client.predict(
|
150 |
+
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.',
|
151 |
+
0.9,
|
152 |
+
256,
|
153 |
+
0.9,
|
154 |
+
1.2,
|
155 |
+
api_name="/chat"
|
156 |
+
)
|
157 |
+
pattern = r'(\d+)%'
|
158 |
+
match = re.search(pattern, result)
|
159 |
+
if match:
|
160 |
+
score = int(match.group(1))
|
161 |
+
scores.append(score)
|
162 |
+
else:
|
163 |
+
scores.append(85)
|
164 |
+
|
165 |
+
def calculate_average(numbers):
|
166 |
+
if not numbers:
|
167 |
+
return 0 # Return 0 for an empty list to avoid division by zero.
|
168 |
+
|
169 |
+
total = sum(numbers)
|
170 |
+
average = total / len(numbers)
|
171 |
+
return average
|
172 |
+
|
173 |
+
# Calculate and display the average score
|
174 |
+
average_score = calculate_average(scores)
|
175 |
+
st.write(f'Your average score is {average_score}')
|