Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,8 +50,14 @@ def extract_student_name(text):
|
|
| 50 |
|
| 51 |
# Function to extract questions from the text
|
| 52 |
def extract_questions_from_text(text):
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
questions = [q for q in questions if not any(keyword in q.lower() for keyword in ['name', 'roll no', 'school'])]
|
|
|
|
| 55 |
return questions
|
| 56 |
|
| 57 |
# Streamlit Interface
|
|
@@ -71,6 +77,10 @@ if uploaded_file is not None:
|
|
| 71 |
if not text: # If no text extracted, try OCR
|
| 72 |
text = extract_text_from_image_pdf("uploaded_file.pdf")
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
# Preprocess text
|
| 75 |
preprocessed_text = preprocess_text(text)
|
| 76 |
|
|
@@ -93,4 +103,3 @@ if uploaded_file is not None:
|
|
| 93 |
st.write(f"**Score**: {result['score']:.2f}")
|
| 94 |
st.write(f"**Feedback**: {result['feedback']}")
|
| 95 |
st.write("---")
|
| 96 |
-
|
|
|
|
| 50 |
|
| 51 |
# Function to extract questions from the text
|
| 52 |
def extract_questions_from_text(text):
|
| 53 |
+
# Improved logic: extract sentences ending with '?' or "Question: [text]"
|
| 54 |
+
questions = re.findall(r'(Question\s*[:|-]?\s*[\w\s\?]+)', text) # Extract questions starting with "Question:"
|
| 55 |
+
questions += re.findall(r'([^.]*\?)', text) # Also extract any sentence ending with "?"
|
| 56 |
+
|
| 57 |
+
# Remove duplicates and metadata like 'Name', 'Roll No', etc.
|
| 58 |
+
questions = list(set(questions)) # Remove duplicates
|
| 59 |
questions = [q for q in questions if not any(keyword in q.lower() for keyword in ['name', 'roll no', 'school'])]
|
| 60 |
+
|
| 61 |
return questions
|
| 62 |
|
| 63 |
# Streamlit Interface
|
|
|
|
| 77 |
if not text: # If no text extracted, try OCR
|
| 78 |
text = extract_text_from_image_pdf("uploaded_file.pdf")
|
| 79 |
|
| 80 |
+
# Print the extracted text to manually check what was extracted (optional)
|
| 81 |
+
st.subheader("Extracted Text:")
|
| 82 |
+
st.text(text)
|
| 83 |
+
|
| 84 |
# Preprocess text
|
| 85 |
preprocessed_text = preprocess_text(text)
|
| 86 |
|
|
|
|
| 103 |
st.write(f"**Score**: {result['score']:.2f}")
|
| 104 |
st.write(f"**Feedback**: {result['feedback']}")
|
| 105 |
st.write("---")
|
|
|