Delete crewai_flashcard.py

#3
by Pavaas - opened
Files changed (1) hide show
  1. crewai_flashcard.py +0 -104
crewai_flashcard.py DELETED
@@ -1,104 +0,0 @@
1
- import os
2
- from crewai import Agent, Task, Crew
3
- from crewai_tools import PDFSearchTool
4
- import openai
5
-
6
- # Ensure your OpenAI API key and model settings are set
7
- openai.api_key = os.getenv("OPENAI_API_KEY")
8
-
9
- # Initialize the PDFSearchTool without a preset PDF
10
- pdf_tool = PDFSearchTool()
11
-
12
- # Agent 1: PDF Extractor Agent – extracts text from the specified page range.
13
- pdf_extractor = Agent(
14
- role="PDF Extractor",
15
- goal="Extract the text content from the specified page range of the provided PDF.",
16
- backstory="You specialize in reading and processing PDFs to return useful study content.",
17
- verbose=True,
18
- tools=[pdf_tool]
19
- )
20
-
21
- # Agent 2: Flashcard Generator Agent – generates flashcards based on extracted text.
22
- flashcard_generator = Agent(
23
- role="Flashcard Generator",
24
- goal="Generate flashcards with questions and answers based on the extracted text.",
25
- backstory="You create study flashcards to test understanding, ensuring each flashcard has a clear question and answer.",
26
- verbose=True
27
- )
28
-
29
- # Task 1: Extraction Task – Extract text from pages {page_range} of the PDF.
30
- extraction_task = Task(
31
- description=(
32
- "Extract and return the text content from the PDF located at {pdf_file_path}."
33
- ),
34
- expected_output="A string containing the extracted text from the specified pages.",
35
- agent=pdf_extractor
36
- )
37
-
38
- # Task 2: Flashcard Generation Task – Generate {flashcard_count} flashcards from the extracted text.
39
- flashcard_task = Task(
40
- description=(
41
- "Based on the following extracted text"
42
- "Generate {flashcard_count} flashcards. Each flashcard should have a question and a corresponding answer. "
43
- "Return the flashcards as a JSON list of objects with keys 'question' and 'answer'."
44
- ),
45
- expected_output="A JSON list of flashcards.",
46
- output_file="flashcards.json",
47
- agent=flashcard_generator,
48
- context=[extraction_task]
49
- )
50
-
51
-
52
- # In crewai_flashcard.py
53
-
54
- # # Task 1: Extraction Task – Extract text from pages {page_range} of the PDF.
55
- # extraction_task = Task(
56
- # description=(
57
- # "Extract and return the text content from pages page_range of the PDF located at pdf_file_path."
58
- # ),
59
- # expected_output="A string containing the extracted text from the specified pages.",
60
- # agent=pdf_extractor
61
- # )
62
-
63
- # # Task 2: Flashcard Generation Task – Generate {flashcard_count} flashcards from the extracted text.
64
- # flashcard_task = Task(
65
- # description=(
66
- # "Based on the following extracted text:"
67
- # "Generate {flashcard_count} flashcards. Each flashcard should have a question and a corresponding answer. "
68
- # "Return the flashcards as a JSON list of objects with keys 'question' and 'answer'."
69
- # ),
70
- # expected_output="A JSON list of flashcards.",
71
- # agent=flashcard_generator,
72
- # context=[extraction_task]
73
- # )
74
-
75
-
76
-
77
-
78
- # Assemble the Crew
79
- flashcard_crew = Crew(
80
- agents=[pdf_extractor, flashcard_generator],
81
- tasks=[extraction_task, flashcard_task],
82
- verbose=True
83
- )
84
-
85
- def generate_flashcards( pdf_file_path: str,flashcard_count: int):
86
- #generate_flashcards(pdf_file_path: str, page_range: str, flashcard_count: int):
87
- """
88
- Run the CrewAI system to extract text from specified pages and generate flashcards.
89
-
90
- Args:
91
- pdf_file_path (str): Path to the PDF file.
92
- page_range (str): Page range to extract text from (e.g., "1-5").
93
- flashcard_count (int): Number of flashcards to generate.
94
-
95
- Returns:
96
- str: JSON string containing the flashcards.
97
- """
98
- inputs = {
99
- "pdf_file_path": pdf_file_path,
100
- #"page_range": page_range,
101
- "flashcard_count": flashcard_count
102
- }
103
- results = flashcard_crew.kickoff(inputs=inputs)
104
- return results.raw #[flashcard_task.id]