Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,22 +5,13 @@ from docx import Document
|
|
| 5 |
import fitz # PyMuPDF
|
| 6 |
import google.generativeai as genai
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
text = ""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
for page in doc:
|
| 16 |
-
text += page.get_text()
|
| 17 |
-
elif filename.endswith('.docx'):
|
| 18 |
-
# Extract text from Word document
|
| 19 |
-
doc = Document(file)
|
| 20 |
-
for paragraph in doc.paragraphs:
|
| 21 |
-
text += paragraph.text + "\n"
|
| 22 |
-
else:
|
| 23 |
-
text = "Unsupported file format. Please upload a PDF or Word document."
|
| 24 |
return text
|
| 25 |
|
| 26 |
def create_multiple_choice_prompt(num_questions, quiz_context, expertise):
|
|
@@ -204,9 +195,9 @@ def main():
|
|
| 204 |
load_dotenv()
|
| 205 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 206 |
|
| 207 |
-
uploaded_file = st.file_uploader("Upload a PDF
|
| 208 |
if uploaded_file is not None:
|
| 209 |
-
text =
|
| 210 |
num_questions = st.number_input("Enter the number of questions", min_value=1, max_value=10, value=3)
|
| 211 |
quiz_type = st.selectbox("Select the type of Question", ["multiple-choice", "true-false", "open-ended", "fill-in-the-blank", "mixed"])
|
| 212 |
expertise = st.text_input("Enter the domain of the questions to be generated.")
|
|
@@ -235,4 +226,4 @@ def main():
|
|
| 235 |
st.markdown(st.session_state.answers)
|
| 236 |
|
| 237 |
if __name__ == "__main__":
|
| 238 |
-
main()
|
|
|
|
| 5 |
import fitz # PyMuPDF
|
| 6 |
import google.generativeai as genai
|
| 7 |
|
| 8 |
+
|
| 9 |
+
def extract_text_from_pdf(file):
|
| 10 |
+
"""Extract text from PDF."""
|
| 11 |
text = ""
|
| 12 |
+
doc = fitz.open(stream=file.read(), filetype="pdf")
|
| 13 |
+
for page in doc:
|
| 14 |
+
text += page.get_text()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return text
|
| 16 |
|
| 17 |
def create_multiple_choice_prompt(num_questions, quiz_context, expertise):
|
|
|
|
| 195 |
load_dotenv()
|
| 196 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 197 |
|
| 198 |
+
uploaded_file = st.file_uploader("Upload a PDF document", type=["pdf"])
|
| 199 |
if uploaded_file is not None:
|
| 200 |
+
text = extract_text_from_pdf(uploaded_file)
|
| 201 |
num_questions = st.number_input("Enter the number of questions", min_value=1, max_value=10, value=3)
|
| 202 |
quiz_type = st.selectbox("Select the type of Question", ["multiple-choice", "true-false", "open-ended", "fill-in-the-blank", "mixed"])
|
| 203 |
expertise = st.text_input("Enter the domain of the questions to be generated.")
|
|
|
|
| 226 |
st.markdown(st.session_state.answers)
|
| 227 |
|
| 228 |
if __name__ == "__main__":
|
| 229 |
+
main()
|