BillBojangeles2000 commited on
Commit
9ca337b
·
1 Parent(s): 9750c43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -46
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 = "Canada"
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
- # Use Gradio for user input and scoring
132
- scores = []
133
- client = Client("https://billbojangeles2000-zephyr-7b-alpha-chatbot-karki.hf.space/")
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'{question}: ')
149
- if res:
150
- result = client.predict(
151
- 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.',
152
- 0.9,
153
- 256,
154
- 0.9,
155
- 1.2,
156
- api_name="/chat"
157
- )
158
- pattern = r'(\d+)%'
159
- match = re.search(pattern, result)
160
- if match:
161
- score = int(match.group(1))
162
- scores.append(score)
163
- else:
164
- scores.append(85)
165
-
166
- def calculate_average(numbers):
167
- if not numbers:
168
- return 0 # Return 0 for an empty list to avoid division by zero.
169
-
170
- total = sum(numbers)
171
- average = total / len(numbers)
172
- return average
173
-
174
- # Calculate and display the average score
175
- average_score = calculate_average(scores)
176
- st.write(f'Your average score is {average_score}')
 
 
 
 
 
 
 
 
 
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}')