BillBojangeles2000 commited on
Commit
987bab3
·
1 Parent(s): 8c0f868

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -50
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
- # Example usage
130
- data = ' '.join(paragraphs)
131
- noOfQues = 5
132
 
133
- subjective_generator = SubjectiveTest(data, noOfQues)
134
- questions = subjective_generator.generate_test("")
 
 
135
 
136
- # Create a form for the quiz
137
- st.write("Fill out the quiz:")
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
- if st.button("Submit"):
144
- scores = []
145
- client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
 
 
 
146
 
147
- question_list = subjective_generator.generate_test(topic) # Define 'questions' here
148
- questions = []
149
- for i, question in enumerate(question_list):
150
- if "Explain" not in question and len(tool.check(question)) == 0 and grammar_sense(question):
151
- questions.append(f"Question: {question}")
152
 
153
- for i, question in enumerate(questions):
154
- res = answers[f'Q{i + 1}']
155
- if res:
156
- result = client.predict(
157
- 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.',
158
- 0.9,
159
- 256,
160
- 0.9,
161
- 1.2,
162
- api_name="/chat"
163
- )
164
- pattern = r'(\d+)%'
165
- match = re.search(pattern, result)
166
- if match:
167
- score = int(match.group(1))
168
- scores.append(score)
169
- else:
170
- scores.append(85)
171
-
172
- def calculate_average(numbers):
173
- if not numbers:
174
- return 0 # Return 0 for an empty list to avoid division by zero.
175
-
176
- total = sum(numbers)
177
- average = total / len(numbers)
178
- return average
179
-
180
- # Calculate and display the average score
181
- average_score = calculate_average(scores)
182
- st.write(f'Your average score is {average_score}')
 
 
 
 
 
 
 
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}')