File size: 2,971 Bytes
5c14889
 
 
 
 
86ef765
901814c
 
 
86ef765
901814c
 
 
 
 
 
86ef765
901814c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86ef765
901814c
86ef765
901814c
 
 
 
 
86ef765
901814c
 
 
 
 
86ef765
901814c
 
 
 
86ef765
e33d320
901814c
 
 
 
 
86ef765
901814c
 
 
 
 
 
 
 
86ef765
901814c
 
 
 
 
 
 
 
 
 
 
 
 
 
e33d320
 
 
 
 
86ef765
 
901814c
 
 
 
 
ee283c4
 
901814c
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
import os
import sys

sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

import gradio as gr
from gradio.themes import Soft
from gradio.themes.utils import colors, fonts, sizes
from services.summarizer import summarize_document

colors.orange_red = colors.Color(
    name="orange_red",
    c50="#FFF0E5", c100="#FFE0CC", c200="#FFC299", c300="#FFA366",
    c400="#FF8533", c500="#FF4500", c600="#E63E00", c700="#CC3700",
    c800="#B33000", c900="#992900", c950="#802200",
)

class OrangeRedTheme(Soft):
    def __init__(self):
        super().__init__(
            primary_hue=colors.orange_red,
            secondary_hue=colors.orange_red,
            neutral_hue=colors.slate,
            text_size=sizes.text_lg,
            font=(fonts.GoogleFont("Outfit"), "Arial", "sans-serif"),
            font_mono=(fonts.GoogleFont("IBM Plex Mono"), "monospace"),
        )
        super().set(
            body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
            button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
            button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
            button_primary_text_color="white",
            block_border_width="3px",
            block_shadow="*shadow_drop_lg",
        )

orange_red_theme = OrangeRedTheme()

css_style = """
#container {
    max-width: 1280px;   /* wider layout */
    margin: auto;
}

@media (min-width: 1600px) {
    #container {
        max-width: 1440px;
    }
}

#title h1 {
    font-size: 2.4em !important;
}
"""

with gr.Blocks(title="AI Document Summarizer") as demo:
    with gr.Column(elem_id="container"):
        gr.Markdown("# **AI Document Summarizer**", elem_id="title")
        gr.Markdown(
            "Summarize **PDF, DOCX, TXT** documents using **Qwen2.5-7B-Instruct** via Hugging Face."
        )

        with gr.Row(equal_height=True):
            # LEFT
            with gr.Column():
                file_input = gr.File(
                    label="Upload Document",
                    file_types=[".pdf", ".docx", ".txt"],
                    type="filepath",
                )

                summarize_btn = gr.Button("Generate Summary", variant="primary")

            # RIGHT
            with gr.Column():
                output = gr.Textbox(
                    label="Summary",
                    lines=18,
                    placeholder="Summary will appear here...",
                )

        gr.Markdown(
            "*Powered by Hugging Face Inference API · Free tier rate limits apply*"
        )

        summarize_btn.click(
            fn=summarize_document,
            inputs=file_input,
            outputs=output,
        )

if __name__ == "__main__":
    demo.queue().launch(
        theme=orange_red_theme,
        css=css_style,
        show_error=True,
        server_name="0.0.0.0",
        server_port=7860,
        debug=True
    )