File size: 6,505 Bytes
a7c4658
 
 
 
87e0312
 
 
 
a7c4658
87e0312
 
cb3a63b
87e0312
a7c4658
87e0312
 
 
 
 
 
a7c4658
87e0312
a7c4658
 
87e0312
 
 
 
 
 
 
a7c4658
87e0312
a7c4658
 
 
87e0312
 
a7c4658
87e0312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7c4658
 
 
87e0312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7c4658
87e0312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7c4658
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import streamlit as st
import json
from datetime import datetime
from transformers import pipeline
from diffusers import StableDiffusionPipeline
import torch
from io import BytesIO
import base64

# Page configuration
st.set_page_config(page_title="ReportRocket: Harvard-Style", page_icon="🚀", layout="wide")

# Initialize AI models
@st.cache_resource
def load_models():
    return {
        'text_generator': pipeline('text-generation', model='distilgpt2'),
        'summarizer': pipeline('summarization', model='facebook/bart-large-cnn'),
        'image_generator': StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")
    }

models = load_models()

# Initialize session state
if 'project_title' not in st.session_state:
    st.session_state.project_title = ""
if 'project_description' not in st.session_state:
    st.session_state.project_description = ""
if 'report_sections' not in st.session_state:
    st.session_state.report_sections = {
        'Abstract': '',
        'Introduction': '',
        'Literature Review': '',
        'Methodology': '',
        'Results': '',
        'Discussion': '',
        'Conclusion': '',
        'References': ''
    }
if 'images' not in st.session_state:
    st.session_state.images = []

# Function to generate table of contents
def generate_table_of_contents():
    toc = "# Table of Contents\n\n"
    for i, section in enumerate(st.session_state.report_sections.keys(), 1):
        toc += f"{i}. [{section}](#{section.lower().replace(' ', '-')})\n"
    return toc

# Function to generate images using Stable Diffusion
@st.cache_data
def generate_images(prompt, num_images=3):
    images = []
    for _ in range(num_images):
        image = models['image_generator'](prompt, num_inference_steps=50).images[0]
        buffered = BytesIO()
        image.save(buffered, format="PNG")
        img_str = base64.b64encode(buffered.getvalue()).decode()
        images.append(f"data:image/png;base64,{img_str}")
    return images

# Main UI
st.title("🚀 ReportRocket: Harvard-Style Project Report Generator")

# Project Input Section
st.header("Project Details")
project_title = st.text_input("Project Title", st.session_state.project_title)
project_description = st.text_area("Project Description", st.session_state.project_description, height=150)

if st.button("Generate Report Structure and Images"):
    if project_title and project_description:
        with st.spinner("Generating report structure and images..."):
            st.session_state.project_title = project_title
            st.session_state.project_description = project_description
            
            # Generate abstract
            abstract = models['summarizer'](project_description, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
            st.session_state.report_sections['Abstract'] = abstract
            
            # Generate other sections (placeholder logic, expand as needed)
            for section in st.session_state.report_sections:
                if section != 'Abstract' and not st.session_state.report_sections[section]:
                    st.session_state.report_sections[section] = f"Generated content for {section} based on project description."
            
            # Generate images
            st.session_state.images = generate_images(project_title)
            
        st.success("Report structure generated and images created successfully!")
    else:
        st.error("Please provide both project title and description.")

# Display Table of Contents
st.header("Table of Contents")
st.markdown(generate_table_of_contents())

# Report Editing Section
st.header("Report Sections")
selected_section = st.selectbox("Select a section to edit:", list(st.session_state.report_sections.keys()))

st.session_state.report_sections[selected_section] = st.text_area(
    f"Edit {selected_section}:", 
    st.session_state.report_sections[selected_section], 
    height=300
)

# Display Images
st.header("Project Images")
if st.session_state.images:
    cols = st.columns(len(st.session_state.images))
    for i, img_data in enumerate(st.session_state.images):
        cols[i].image(img_data)
else:
    st.info("No images generated yet. Generate report structure to create images.")

# AI Assistance
if st.button("Generate Content for Section"):
    with st.spinner("Generating content..."):
        prompt = f"Generate content for {selected_section} of a project titled '{st.session_state.project_title}'"
        generated_text = models['text_generator'](prompt, max_length=200, num_return_sequences=1)[0]['generated_text']
        st.session_state.report_sections[selected_section] += "\n" + generated_text
        st.success("Content generated. Please review and edit as needed.")
        st.experimental_rerun()

# Additional Features
st.header("Additional Features")

# ER Diagram Generator (placeholder)
if st.button("Generate ER Diagram"):
    st.info("ER Diagram generation feature is under development.")

# Plagiarism Check (placeholder)
if st.button("Check for Plagiarism"):
    st.info("Plagiarism check feature is under development.")

# Paraphrasing Tool
if st.button("Paraphrase Selected Section"):
    with st.spinner("Paraphrasing..."):
        paraphrased_text = models['summarizer'](st.session_state.report_sections[selected_section], max_length=len(st.session_state.report_sections[selected_section].split()), min_length=10, do_sample=True)[0]['summary_text']
        st.session_state.report_sections[selected_section] = paraphrased_text
        st.success("Content paraphrased. Please review and edit as needed.")
        st.experimental_rerun()

# Save and Download
if st.button("Save and Download Report"):
    report_data = {
        "title": st.session_state.project_title,
        "description": st.session_state.project_description,
        "table_of_contents": generate_table_of_contents(),
        "sections": st.session_state.report_sections,
        "images": st.session_state.images,
        "timestamp": datetime.now().isoformat()
    }
    json_data = json.dumps(report_data, indent=2)
    st.download_button(
        label="Download Report as JSON",
        file_name=f"{st.session_state.project_title.replace(' ', '_')}_report.json",
        mime="application/json",
        data=json_data
    )
    st.success("Report saved and ready for download!")

# Footer
st.markdown("---")
st.markdown("Built with ❤️ using Streamlit and Hugging Face")