cstr commited on
Commit
d078a09
·
verified ·
1 Parent(s): 27661e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -5,7 +5,7 @@ from gradio_client import Client, handle_file
5
  API_URL = "ellamind/sui-demo"
6
 
7
  # ============================================================================
8
- # Theme & Styling (Fixed for Dark Mode)
9
  # ============================================================================
10
 
11
  THEME = gr.themes.Soft(
@@ -45,7 +45,6 @@ CSS = """
45
  padding-bottom: 0.5rem;
46
  }
47
 
48
- /* Thinking/Reasoning block inside the summary markdown */
49
  .thinking-section {
50
  background: var(--secondary-50);
51
  border-left: 4px solid var(--primary-500);
@@ -56,7 +55,6 @@ CSS = """
56
  color: var(--body-text-color-subdued);
57
  }
58
 
59
- /* Specific fix for dark mode reasoning block */
60
  [data-theme="dark"] .thinking-section {
61
  background: var(--neutral-800);
62
  }
@@ -86,17 +84,16 @@ CSS = """
86
  # ============================================================================
87
 
88
  def summarize_proxy(pdf_file, language, words, custom_instruction):
89
- """Calls the backend Space API and yields results."""
90
  if not pdf_file:
 
91
  yield "Please upload a PDF document.", "", gr.update(visible=False)
92
  return
93
 
94
  try:
95
- # Initialize the client pointing to the demo space
96
  client = Client(API_URL)
97
 
98
- # Use the 'summarize' API endpoint (index 0 in your config)
99
- # Note: handle_file is necessary for Gradio 5.0+ to process local files correctly
100
  job = client.submit(
101
  pdf_file=handle_file(pdf_file),
102
  language=language,
@@ -105,20 +102,25 @@ def summarize_proxy(pdf_file, language, words, custom_instruction):
105
  api_name="/summarize"
106
  )
107
 
108
- # Iterate through the generator responses for streaming
109
  for result in job:
110
- # Result is a tuple: (formatted_output, sources_md, accordion_update)
111
- yield result
 
 
 
 
 
112
 
113
  except Exception as e:
114
- yield f"### API Error\n{str(e)}", "Please ensure the backend Space is active.", gr.update(visible=False)
115
 
116
  # ============================================================================
117
  # Interface
118
  # ============================================================================
119
 
120
  def create_app():
121
- with gr.Blocks(title="sui-1-24b", theme=THEME, css=CSS) as app:
 
122
 
123
  gr.HTML("""
124
  <div class="main-header">
@@ -128,7 +130,6 @@ def create_app():
128
  """)
129
 
130
  with gr.Row(equal_height=False):
131
- # Left: Inputs
132
  with gr.Column(scale=2):
133
  gr.Markdown("### Document", elem_classes=["section-title"])
134
  pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
@@ -148,14 +149,11 @@ def create_app():
148
 
149
  generate_btn = gr.Button("Generate Summary", variant="primary", elem_classes=["generate-btn"])
150
 
151
- # Right: Outputs
152
  with gr.Column(scale=3):
153
  gr.Markdown("### Summary", elem_classes=["section-title"])
154
- summary_output = gr.Markdown(
155
- value="*Upload a PDF to begin.*",
156
- container=True
157
- )
158
 
 
159
  with gr.Accordion("View Source Citations", open=False, visible=False) as sources_accordion:
160
  sources_output = gr.Markdown(elem_classes=["sources-panel"])
161
 
@@ -174,4 +172,5 @@ def create_app():
174
  return app
175
 
176
  if __name__ == "__main__":
177
- create_app().launch()
 
 
5
  API_URL = "ellamind/sui-demo"
6
 
7
  # ============================================================================
8
+ # Theme & Styling
9
  # ============================================================================
10
 
11
  THEME = gr.themes.Soft(
 
45
  padding-bottom: 0.5rem;
46
  }
47
 
 
48
  .thinking-section {
49
  background: var(--secondary-50);
50
  border-left: 4px solid var(--primary-500);
 
55
  color: var(--body-text-color-subdued);
56
  }
57
 
 
58
  [data-theme="dark"] .thinking-section {
59
  background: var(--neutral-800);
60
  }
 
84
  # ============================================================================
85
 
86
  def summarize_proxy(pdf_file, language, words, custom_instruction):
87
+ """Calls the backend Space API and yields exactly 3 results."""
88
  if not pdf_file:
89
+ # Yielding 3 values to match the interface components
90
  yield "Please upload a PDF document.", "", gr.update(visible=False)
91
  return
92
 
93
  try:
 
94
  client = Client(API_URL)
95
 
96
+ # We start the stream. The backend yields 3 objects: (summary, sources, accordion_update)
 
97
  job = client.submit(
98
  pdf_file=handle_file(pdf_file),
99
  language=language,
 
102
  api_name="/summarize"
103
  )
104
 
 
105
  for result in job:
106
+ # Result from the client should be a list/tuple of 3 items
107
+ # But let's be safe and ensure it matches the 3 outputs
108
+ if len(result) == 3:
109
+ yield result[0], result[1], result[2]
110
+ else:
111
+ # Fallback in case backend returns unexpected shape
112
+ yield result[0], result[1], gr.update(visible=True)
113
 
114
  except Exception as e:
115
+ yield f"### API Error\n{str(e)}", "Ensure the backend Space is active.", gr.update(visible=False)
116
 
117
  # ============================================================================
118
  # Interface
119
  # ============================================================================
120
 
121
  def create_app():
122
+ # Removed theme and css from constructor for Gradio 6.0 compatibility
123
+ with gr.Blocks(title="sui-1-24b") as app:
124
 
125
  gr.HTML("""
126
  <div class="main-header">
 
130
  """)
131
 
132
  with gr.Row(equal_height=False):
 
133
  with gr.Column(scale=2):
134
  gr.Markdown("### Document", elem_classes=["section-title"])
135
  pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
 
149
 
150
  generate_btn = gr.Button("Generate Summary", variant="primary", elem_classes=["generate-btn"])
151
 
 
152
  with gr.Column(scale=3):
153
  gr.Markdown("### Summary", elem_classes=["section-title"])
154
+ summary_output = gr.Markdown(value="*Upload a PDF to begin.*")
 
 
 
155
 
156
+ # Note: This is output #3
157
  with gr.Accordion("View Source Citations", open=False, visible=False) as sources_accordion:
158
  sources_output = gr.Markdown(elem_classes=["sources-panel"])
159
 
 
172
  return app
173
 
174
  if __name__ == "__main__":
175
+ # Theme and CSS passed here to comply with Gradio 6.0 warning
176
+ create_app().launch(theme=THEME, css=CSS)