File size: 6,613 Bytes
27661e4
 
 
 
 
 
 
d078a09
27661e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62d06f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17f7aab
27661e4
17f7aab
 
 
 
 
 
27661e4
 
17f7aab
 
 
 
62d06f3
 
17f7aab
 
 
 
62d06f3
17f7aab
 
 
 
 
 
 
27661e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d078a09
27661e4
d078a09
27661e4
 
 
 
 
 
d078a09
27661e4
 
 
 
 
 
 
 
 
d078a09
 
 
 
 
 
 
27661e4
 
d078a09
27661e4
 
 
 
 
 
d078a09
 
27661e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d078a09
27661e4
d078a09
27661e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d078a09
 
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import gradio as gr
from gradio_client import Client, handle_file

# Target Space API
API_URL = "ellamind/sui-demo"

# ============================================================================
# Theme & Styling
# ============================================================================

THEME = gr.themes.Soft(
    primary_hue="slate",
    secondary_hue="slate",
    neutral_hue="slate",
    font=gr.themes.GoogleFont("Inter"),
).set(
    block_radius="0.75rem",
    block_shadow="0 1px 3px 0 rgb(0 0 0 / 0.1)",
    button_primary_background_fill="*primary_800",
    button_primary_background_fill_hover="*primary_700",
)

CSS = """
.gradio-container {
    max-width: 1100px !important;
    margin: 0 auto !important;
    padding-top: 2rem !important;
}

.main-header {
    text-align: center;
    margin-bottom: 2rem;
}

.main-header h1 {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--body-text-color);
}

.section-title {
    margin-bottom: 1rem !important;
    border-bottom: 1px solid var(--border-color-primary);
    padding-bottom: 0.5rem;
}

.output-panel {
    background: var(--block-background-fill) !important;
    border-radius: 0.75rem !important;
    border: 1px solid var(--border-color-primary) !important;
    padding: 1.5rem !important;
    min-height: 400px;
}

.summary-text {
    font-size: 1.05rem !important;
    line-height: 1.8 !important;
    color: var(--body-text-color) !important;
    background: transparent !important;
}

/* 1. Base style (Light Mode) */
.thinking-section {
    background: rgba(0, 0, 0, 0.05) !important; /* Subtle tint instead of var */
    border-left: 4px solid var(--primary-500) !important;
    padding: 1.25rem !important;
    margin-bottom: 1.5rem !important;
    border-radius: 0 0.75rem 0.75rem 0 !important;
    font-style: italic !important;
}

/* 2. Dark Mode Override */
.dark .thinking-section {
    background: rgba(255, 255, 255, 0.1) !important; /* Light tint on dark background */
    border-left-color: var(--primary-400) !important;
}

/* 3. Force the text inside the thinking section to adapt */
.thinking-section, 
.thinking-section p, 
.thinking-section span {
    color: var(--body-text-color) !important;
    opacity: 0.9;
}

/* 4. Extra insurance for the summary area text in dark mode */
.dark .summary-text, 
.dark .prose {
    color: #f1f5f9 !important; /* Explicit light gray/white */
}

.sources-panel {
    font-size: 0.9rem !important;
    max-height: 400px;
    overflow-y: auto;
}

.generate-btn {
    margin-top: 1rem;
    font-weight: 600 !important;
}

.footer {
    text-align: center;
    margin-top: 3rem;
    padding-bottom: 2rem;
    font-size: 0.85rem;
    opacity: 0.6;
}
"""

# ============================================================================
# API Proxy Function
# ============================================================================

def summarize_proxy(pdf_file, language, words, custom_instruction):
    """Calls the backend Space API and yields exactly 3 results."""
    if not pdf_file:
        # Yielding 3 values to match the interface components
        yield "Please upload a PDF document.", "", gr.update(visible=False)
        return

    try:
        client = Client(API_URL)
        
        # We start the stream. The backend yields 3 objects: (summary, sources, accordion_update)
        job = client.submit(
            pdf_file=handle_file(pdf_file),
            language=language,
            words=words,
            custom_instruction=custom_instruction,
            api_name="/summarize"
        )

        for result in job:
            # Result from the client should be a list/tuple of 3 items
            # But let's be safe and ensure it matches the 3 outputs
            if len(result) == 3:
                yield result[0], result[1], result[2]
            else:
                # Fallback in case backend returns unexpected shape
                yield result[0], result[1], gr.update(visible=True)

    except Exception as e:
        yield f"### API Error\n{str(e)}", "Ensure the backend Space is active.", gr.update(visible=False)

# ============================================================================
# Interface
# ============================================================================

def create_app():
    # Removed theme and css from constructor for Gradio 6.0 compatibility
    with gr.Blocks(title="sui-1-24b") as app:
        
        gr.HTML("""
        <div class="main-header">
            <h1>sui-1-24b</h1>
            <p>Grounded summaries with verifiable source citations</p>
        </div>
        """)

        with gr.Row(equal_height=False):
            with gr.Column(scale=2):
                gr.Markdown("### Document", elem_classes=["section-title"])
                pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")

                gr.Markdown("### Options", elem_classes=["section-title"])
                language = gr.Dropdown(
                    choices=["English", "German", "Spanish", "French", "Italian"],
                    value="German",
                    label="Language"
                )
                words = gr.Slider(minimum=100, maximum=600, value=150, step=50, label="Summary Length")
                custom_instruction = gr.Textbox(
                    label="Instructions (Optional)", 
                    placeholder="Focus on key findings...", 
                    lines=2
                )
                
                generate_btn = gr.Button("Generate Summary", variant="primary", elem_classes=["generate-btn"])

            with gr.Column(scale=3):
                gr.Markdown("### Summary", elem_classes=["section-title"])
                summary_output = gr.Markdown(value="*Upload a PDF to begin.*")

                # Note: This is output #3
                with gr.Accordion("View Source Citations", open=False, visible=False) as sources_accordion:
                    sources_output = gr.Markdown(elem_classes=["sources-panel"])

        generate_btn.click(
            fn=summarize_proxy,
            inputs=[pdf_input, language, words, custom_instruction],
            outputs=[summary_output, sources_output, sources_accordion],
        )

        gr.HTML("""
        <div class="footer">
            Powered by <a href="https://huggingface.co/ellamind/sui-1-24b" target="_blank">ellamind/sui-1-24b</a> via API
        </div>
        """)
        
    return app

if __name__ == "__main__":
    # Theme and CSS passed here to comply with Gradio 6.0 warning
    create_app().launch(theme=THEME, css=CSS)