File size: 3,367 Bytes
2a1cdbf
f360edc
 
 
 
2a1cdbf
f360edc
2a1cdbf
f360edc
 
 
 
 
bcb80f2
f360edc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcb80f2
f360edc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcb80f2
f360edc
 
 
 
 
 
 
b6788d9
 
f360edc
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
import streamlit as st
from codet5_summarizer import CodeT5Summarizer, MODEL_OPTIONS
import textwrap
import os
import base64

st.set_page_config(page_title="Code Summarizer & Report Generator", layout="wide")

st.title("πŸ“„ Code Summarizer & Report Generator")
st.markdown("""
Upload a Python code file to get a high-level summary and a report structure with editable sections.
You can choose from various models including Mistral, CodeT5, and Gemini.
""")

# Model selection
model_label = st.selectbox("Select Model", list(MODEL_OPTIONS.keys()), index=0)
summarizer = CodeT5Summarizer(model_name=MODEL_OPTIONS[model_label])

# Upload code file
uploaded_file = st.file_uploader("Upload a .py file", type="py")
if uploaded_file:
    code = uploaded_file.read().decode("utf-8")
    st.code(code, language="python")

    st.markdown("---")
    st.subheader("πŸ” Generating Summary...")

    if "Mistral" in model_label or "Gemini" in model_label:
        summary = summarizer.summarize(code)
        function_summaries = None
        class_summaries = None
    else:
        results = summarizer.summarize_code(code)
        summary = results["file_summary"]
        function_summaries = results["function_summaries"]
        class_summaries = results["class_summaries"]

    st.text_area("Summary", summary, height=200)

    if function_summaries:
        st.subheader("🧩 Function Summaries")
        for func, summ in function_summaries.items():
            st.text_area(f"Function: {func}", summ, height=100)

    if class_summaries:
        st.subheader("πŸ—οΈ Class Summaries")
        for cls, summ in class_summaries.items():
            st.text_area(f"Class: {cls}", summ, height=100)

    # Report generation section
    st.markdown("---")
    st.subheader("πŸ“˜ Generate Report")

    default_sections = [
        "Abstract", "Introduction", "Literature Review", "Methodology",
        "Modules", "Software & Hardware Requirements", "Architecture & UML Diagrams",
        "References", "Conclusion"
    ]

    sections = st.multiselect("Select Sections", default_sections, default=default_sections)

    report = ""
    for section in sections:
        content = st.text_area(f"✏️ {section} Content", value=f"{section} description goes here...", height=150)
        report += f"\n## {section}\n\n{textwrap.dedent(content)}\n"

    # Export format
    st.markdown("---")
    st.subheader("πŸ“€ Export Report")
    export_format = st.radio("Select Export Format", ["Markdown", "Text", "HTML"])

    def generate_download_link(content, filename):
        b64 = base64.b64encode(content.encode()).decode()
        return f'<a href="data:file/txt;base64,{b64}" download="{filename}">πŸ“₯ Download {filename}</a>'

    if st.button("Generate Export File"):
        filename = uploaded_file.name.replace(".py", "")
        if export_format == "Markdown":
            st.markdown(generate_download_link(report, f"{filename}_report.md"), unsafe_allow_html=True)
        elif export_format == "Text":
            st.markdown(generate_download_link(report, f"{filename}_report.txt"), unsafe_allow_html=True)
        else:
            html_report = report.replace("\n", "<br>")
            html_content = f"<html><body>{html_report}</body></html>"
            st.markdown(generate_download_link(html_content, f"{filename}_report.html"), unsafe_allow_html=True)