File size: 2,963 Bytes
08a0246
f1e900a
 
 
08a0246
 
f1e900a
08a0246
f1e900a
 
08a0246
f1e900a
 
 
 
08a0246
 
 
 
f1e900a
08a0246
 
f1e900a
 
 
 
 
08a0246
f1e900a
08a0246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1e900a
08a0246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
import streamlit as st
from transformers import pipeline
import os

# Set the page configuration to wide layout
st.set_page_config(layout="wide")

# Initialize the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Define functions for summarizing, extracting key points, and generating flashcards
def summarize_text(text):
    summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
    return summary[0]['summary_text']

def extract_key_points(text):
    summary = summarizer(text, max_length=60, min_length=20, do_sample=False)
    return [point['summary_text'] for point in summary]

def generate_flashcards(text):
    # Assume flashcards are similar to key points in this case
    return extract_key_points(text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()
    summary = summarize_text(text)
    key_points = extract_key_points(text)
    flashcards = generate_flashcards(text)
    return summary, key_points, flashcards

# Define tabs for the application
tab1, tab2 = st.tabs(["Text Summarization", "File Upload & Process"])

# Text Summarization Tab
with tab1:
    st.title("Text Summarization")

    st.subheader("Enter Your Text")
    user_text = st.text_area("Input Text", height=300)

    if st.button("Generate Summary"):
        if user_text:
            summary = summarize_text(user_text)
            key_points = extract_key_points(user_text)
            flashcards = generate_flashcards(user_text)

            st.write("### Summary")
            st.write(summary)

            st.write("### Key Points")
            for idx, point in enumerate(key_points, start=1):
                st.write(f"**Point {idx}:** {point}")

            st.write("### Flashcards")
            for idx, card in enumerate(flashcards, start=1):
                st.write(f"**Flashcard {idx}:** {card}")
        else:
            st.warning("Please enter text to generate a summary.")

# File Upload & Process Tab
with tab2:
    st.title("Upload and Process File")

    uploaded_file = st.file_uploader("Choose a text file", type=["txt"])

    if uploaded_file is not None:
        # Save uploaded file temporarily
        file_path = os.path.join("uploads", uploaded_file.name)
        with open(file_path, "wb") as f:
            f.write(uploaded_file.getbuffer())

        # Process the file
        summary, key_points, flashcards = process_file(file_path)

        # Display the summary, key points, and flashcards
        st.write("### Summary")
        st.write(summary)

        st.write("### Key Points")
        for idx, point in enumerate(key_points, start=1):
            st.write(f"**Point {idx}:** {point}")

        st.write("### Flashcards")
        for idx, card in enumerate(flashcards, start=1):
            st.write(f"**Flashcard {idx}:** {card}")

        # Clean up the temporary file
        os.remove(file_path)