Files changed (1) hide show
  1. app1.py +0 -55
app1.py DELETED
@@ -1,55 +0,0 @@
1
- # app.py
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")
9
-
10
- st.write("Upload a PDF, specify a page range (e.g. '1' or '1-5'), and choose the number of flashcards to generate.")
11
-
12
- # PDF uploader
13
- uploaded_file = st.file_uploader("Upload PDF file", type="pdf")
14
- page_range = st.text_input("Enter page range to extract (e.g. '1-5' or '1'):")
15
- flashcard_count = st.number_input("Number of flashcards to generate:", min_value=1, max_value=20, value=5, step=1)
16
-
17
- if uploaded_file is not None and page_range:
18
- # Save the uploaded file to a temporary file
19
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
20
- tmp.write(uploaded_file.read())
21
- pdf_file_path = tmp.name
22
-
23
- st.success("PDF uploaded successfully!")
24
-
25
- if st.button("Generate Flashcards"):
26
- with st.spinner("Generating flashcards..."):
27
- # This function call will run the CrewAI crew,
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 = []
47
-
48
- st.subheader("Generated Flashcards")
49
- if flashcards:
50
- for idx, card in enumerate(flashcards):
51
- st.markdown(f"**Flashcard {idx+1}:**")
52
- st.write(f"**Question:** {card.get('question', '')}")
53
- st.write(f"**Answer:** {card.get('answer', '')}")
54
- else:
55
- st.write("No flashcards generated.")