-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathapp.py
80 lines (63 loc) · 2.21 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from transformers import pipeline
import spacy
import nltk
from nltk.tokenize import sent_tokenize
nltk.download('punkt')
# Load summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
def summarize_text(text):
summary = summarizer(text, max_length=100, min_length=50, do_sample=False)
return summary[0]['summary_text']
# Example
text = """Your document or article content goes here. Make sure it's a large enough
passage to test the summarizer properly."""
print("Summary:", summarize_text(text))
nlp = spacy.load("en_core_web_sm")
def generate_flashcards(text):
doc = nlp(text)
flashcards = []
for sent in doc.sents:
# Extract main entities for Q&A pairs
entities = [ent.text for ent in sent.ents]
if entities:
question = f"What is {entities[0]}?"
answer = sent.text
flashcards.append((question, answer))
return flashcards
# Example
flashcards = generate_flashcards(text)
for q, a in flashcards:
print("Q:", q)
print("A:", a)
def generate_quiz_questions(text):
questions = []
sentences = sent_tokenize(text)
for sentence in sentences:
if "is" in sentence:
question = sentence.replace("is", "is what")
questions.append(question + "?")
return questions
# Example
questions = generate_quiz_questions(text)
for q in questions:
print("Quiz Question:", q)
def main():
print("Welcome to the AI-Powered Study Assistant!")
text = input("Enter the text you want to study: ")
# Generate summary
print("\nSummarizing text...")
summary = summarize_text(text)
print("Summary:", summary)
# Generate flashcards
print("\nGenerating flashcards...")
flashcards = generate_flashcards(text)
for i, (q, a) in enumerate(flashcards, 1):
print(f"Flashcard {i} - Q: {q}")
print(f" A: {a}")
# Generate quiz questions
print("\nGenerating quiz questions...")
questions = generate_quiz_questions(text)
for i, question in enumerate(questions, 1):
print(f"Question {i}: {question}")
if __name__ == "__main__":
main()