JustusI commited on
Commit
cc79fb0
·
verified ·
1 Parent(s): f842e3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -2,6 +2,7 @@
2
  import streamlit as st
3
  import tempfile
4
  import json
 
5
  from crewai_flashcard import generate_flashcards
6
 
7
  st.title("📚 Flashcard Generator from PDF")
@@ -27,10 +28,19 @@ if uploaded_file is not None and page_range:
27
  # which outputs flashcards.json to the working directory.
28
  generate_flashcards(pdf_file_path, page_range, flashcard_count)
29
 
30
- # Read the flashcards.json file generated by the flashcard task
 
 
 
 
 
 
 
 
31
  try:
32
- with open("flashcards.json", "r") as f:
33
- flashcards = json.load(f)
 
34
  except Exception as e:
35
  st.error(f"Error reading flashcards.json: {e}")
36
  flashcards = []
 
2
  import streamlit as st
3
  import tempfile
4
  import json
5
+ from pathlib import Path
6
  from crewai_flashcard import generate_flashcards
7
 
8
  st.title("📚 Flashcard Generator from PDF")
 
28
  # which outputs flashcards.json to the working directory.
29
  generate_flashcards(pdf_file_path, page_range, flashcard_count)
30
 
31
+ # # Read the flashcards.json file generated by the flashcard task
32
+ # try:
33
+ # with open("flashcards.json", "r") as f:
34
+ # flashcards = json.load(f)
35
+ # except Exception as e:
36
+ # st.error(f"Error reading flashcards.json: {e}")
37
+ # flashcards = []
38
+
39
+ # Alternative method: use pathlib to read the flashcards.json file
40
  try:
41
+ flashcards_path = Path("flashcards.json")
42
+ flashcards_data = flashcards_path.read_text(encoding="utf-8")
43
+ flashcards = json.loads(flashcards_data)
44
  except Exception as e:
45
  st.error(f"Error reading flashcards.json: {e}")
46
  flashcards = []