DevYasa commited on
Commit
a7c4658
Β·
verified Β·
1 Parent(s): 9d32c1b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -0
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ from datetime import datetime
4
+ from transformers import pipeline
5
+
6
+ # Initialize AI model
7
+ @st.cache_resource
8
+ def load_model():
9
+ return pipeline('text-generation', model='distilgpt2')
10
+
11
+ text_generator = load_model()
12
+
13
+ # Page configuration
14
+ st.set_page_config(page_title="ReportRocket", page_icon="πŸš€", layout="wide")
15
+
16
+ # Initialize session state
17
+ if 'report_content' not in st.session_state:
18
+ st.session_state.report_content = {
19
+ 'Introduction': '',
20
+ 'Methodology': '',
21
+ 'Results': '',
22
+ 'Discussion': '',
23
+ 'Conclusion': ''
24
+ }
25
+ if 'report_title' not in st.session_state:
26
+ st.session_state.report_title = "Untitled Report"
27
+
28
+ # Sidebar
29
+ st.sidebar.title('πŸš€ ReportRocket')
30
+ st.sidebar.text('AI-Powered Report Creator')
31
+
32
+ # Navigation
33
+ section = st.sidebar.radio('Navigate to:', list(st.session_state.report_content.keys()))
34
+
35
+ # Main content area
36
+ st.title(f"πŸ“ {st.session_state.report_title}")
37
+ st.subheader(f"Section: {section}")
38
+
39
+ # Report title input
40
+ new_title = st.text_input("Report Title", st.session_state.report_title)
41
+ if new_title != st.session_state.report_title:
42
+ st.session_state.report_title = new_title
43
+ st.success("Title updated!")
44
+
45
+ # Text editor for the current section
46
+ st.session_state.report_content[section] = st.text_area(
47
+ "Edit your content:",
48
+ st.session_state.report_content[section],
49
+ height=300
50
+ )
51
+
52
+ # AI assistance
53
+ if st.button('πŸ€– Generate Content'):
54
+ with st.spinner('Generating content...'):
55
+ try:
56
+ prompt = st.session_state.report_content[section]
57
+ generated_text = text_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
58
+ st.session_state.report_content[section] += "\n" + generated_text
59
+ st.success("Content generated successfully!")
60
+ st.experimental_rerun()
61
+ except Exception as e:
62
+ st.error(f"An error occurred while generating content: {str(e)}")
63
+
64
+ # Save functionality
65
+ if st.button('πŸ’Ύ Save Report'):
66
+ try:
67
+ report_data = {
68
+ "title": st.session_state.report_title,
69
+ "content": st.session_state.report_content,
70
+ "timestamp": datetime.now().isoformat()
71
+ }
72
+ json_data = json.dumps(report_data, indent=2)
73
+ st.download_button(
74
+ label="Download JSON",
75
+ file_name=f"{st.session_state.report_title.replace(' ', '_')}.json",
76
+ mime="application/json",
77
+ data=json_data
78
+ )
79
+ st.success('Report saved successfully!')
80
+ except Exception as e:
81
+ st.error(f"An error occurred while saving the report: {str(e)}")
82
+
83
+ # Load functionality (placeholder)
84
+ st.sidebar.markdown("---")
85
+ st.sidebar.subheader("Load Report")
86
+ uploaded_file = st.sidebar.file_uploader("Choose a file", type="json")
87
+ if uploaded_file is not None:
88
+ try:
89
+ report_data = json.load(uploaded_file)
90
+ st.session_state.report_title = report_data["title"]
91
+ st.session_state.report_content = report_data["content"]
92
+ st.sidebar.success("Report loaded successfully!")
93
+ st.experimental_rerun()
94
+ except Exception as e:
95
+ st.sidebar.error(f"An error occurred while loading the report: {str(e)}")
96
+
97
+ # Placeholder for future features
98
+ st.sidebar.markdown("---")
99
+ st.sidebar.subheader("Additional Features")
100
+ st.sidebar.info("πŸ” Plagiarism Check (Coming Soon)")
101
+ st.sidebar.info("πŸ“Š ER Diagram Generator (Coming Soon)")
102
+
103
+ # Display current report content (for debugging, can be removed in production)
104
+ if st.checkbox("Show current report content"):
105
+ st.write(st.session_state.report_content)
106
+
107
+ # Footer
108
+ st.markdown("---")
109
+ st.markdown("Built with ❀️ using Streamlit and Hugging Face")