Distopia22 commited on
Commit
08eb6be
Β·
1 Parent(s): 14734ba

Feature: Replace API config with upload redirect button

Browse files
Files changed (2) hide show
  1. app.py +28 -42
  2. assets/styles.css +29 -0
app.py CHANGED
@@ -5,20 +5,6 @@ import os
5
 
6
  # ==================== API Functions ====================
7
 
8
- def check_api_health(api_url):
9
- """Check if the backend API is healthy"""
10
- try:
11
- response = requests.get(f"{api_url}/api/v1/health", timeout=10)
12
- response.raise_for_status()
13
- health_data = response.json()
14
- return f"βœ… API is healthy and running!\n\nService: {health_data.get('service', 'ICD-CPT Coding API')}"
15
- except requests.exceptions.Timeout:
16
- return "❌ API Health Check Failed: Request timed out"
17
- except requests.exceptions.RequestException as e:
18
- return f"❌ API Health Check Failed: {str(e)}"
19
- except Exception as e:
20
- return f"❌ Unexpected Error: {str(e)}"
21
-
22
  def analyze_provider_notes(provider_notes, api_url, progress=gr.Progress()):
23
  """Send provider notes to backend API for analysis"""
24
  if not provider_notes or not provider_notes.strip():
@@ -73,10 +59,11 @@ Please enter provider notes in the text box below and click **Send** to analyze.
73
  - Be specific about treatments and prescriptions
74
 
75
  **How to use:**
76
- 1. Select an example from the sidebar
77
- 2. Type your own clinical notes below
78
- 3. Click the **Send** button
79
- 4. Review the ICD-10 and CPT codes generated
 
80
  """
81
 
82
  def format_complete_response(result):
@@ -166,17 +153,24 @@ with gr.Blocks(css=load_css(), theme=gr.themes.Soft(), title="Medical Coding (IC
166
 
167
  gr.Markdown("---")
168
 
169
- # API Configuration
170
- with gr.Accordion("βš™οΈ API Configuration", open=False, elem_classes="api-config"):
171
- api_url_input = gr.Textbox(
172
- label="Backend API URL",
173
- value="https://Distopia22-icd-cpt-coding-api.hf.space",
174
- placeholder="https://your-backend-api.hf.space",
175
- interactive=True
176
- )
177
-
178
- check_api_btn = gr.Button("πŸ” Check API Status", elem_classes="check-api-button", size="sm")
179
- api_status_output = gr.Textbox(label="Status", lines=3, interactive=False)
 
 
 
 
 
 
 
180
 
181
  # Right Chat Area
182
  with gr.Column(scale=3, elem_classes="chat-container"):
@@ -210,35 +204,27 @@ with gr.Blocks(css=load_css(), theme=gr.themes.Soft(), title="Medical Coding (IC
210
  </div>
211
  """)
212
 
213
- # Event Handlers
 
 
214
  for example_name, btn in example_buttons.items():
215
  btn.click(
216
  fn=lambda name=example_name: load_example(name),
217
  outputs=[provider_notes_input]
218
  )
219
 
 
220
  send_btn.click(
221
  fn=analyze_provider_notes,
222
  inputs=[provider_notes_input, api_url_state],
223
  outputs=[output_area]
224
  )
225
 
 
226
  clear_btn.click(
227
  fn=lambda: ("", generate_empty_response()),
228
  outputs=[provider_notes_input, output_area]
229
  )
230
-
231
- check_api_btn.click(
232
- fn=check_api_health,
233
- inputs=[api_url_input],
234
- outputs=[api_status_output]
235
- )
236
-
237
- api_url_input.change(
238
- fn=lambda x: x,
239
- inputs=[api_url_input],
240
- outputs=[api_url_state]
241
- )
242
 
243
  # Launch
244
  if __name__ == "__main__":
 
5
 
6
  # ==================== API Functions ====================
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def analyze_provider_notes(provider_notes, api_url, progress=gr.Progress()):
9
  """Send provider notes to backend API for analysis"""
10
  if not provider_notes or not provider_notes.strip():
 
59
  - Be specific about treatments and prescriptions
60
 
61
  **How to use:**
62
+ 1. Select an example from the sidebar, or
63
+ 2. Upload documents via the Upload button
64
+ 3. Type your own clinical notes below
65
+ 4. Click the **Send** button
66
+ 5. Review the ICD-10 and CPT codes generated
67
  """
68
 
69
  def format_complete_response(result):
 
153
 
154
  gr.Markdown("---")
155
 
156
+ # Upload Document Section - Redirects to API Docs
157
+ gr.HTML('<div class="sidebar-title">πŸ“€ Upload Document</div>')
158
+
159
+ gr.HTML("""
160
+ <a href="https://distopia22-icd-cpt-coding-api-backend.hf.space/docs" target="_blank" style="text-decoration: none;">
161
+ <button class="upload-redirect-button">
162
+ πŸ“ Upload via API Docs
163
+ </button>
164
+ </a>
165
+ <div style="background: rgba(255,255,255,0.1); padding: 10px; border-radius: 8px; margin-top: 10px;">
166
+ <p style="color: #e0f7f4; font-size: 0.8rem; margin: 5px 0; text-align: center;">
167
+ πŸ“ Only .txt format allowed
168
+ </p>
169
+ <p style="color: #ffffff; font-size: 0.75rem; margin: 5px 0; text-align: center; opacity: 0.7;">
170
+ Click button to upload files
171
+ </p>
172
+ </div>
173
+ """)
174
 
175
  # Right Chat Area
176
  with gr.Column(scale=3, elem_classes="chat-container"):
 
204
  </div>
205
  """)
206
 
207
+ # ==================== Event Handlers ====================
208
+
209
+ # Example button clicks
210
  for example_name, btn in example_buttons.items():
211
  btn.click(
212
  fn=lambda name=example_name: load_example(name),
213
  outputs=[provider_notes_input]
214
  )
215
 
216
+ # Send button - Analyze notes
217
  send_btn.click(
218
  fn=analyze_provider_notes,
219
  inputs=[provider_notes_input, api_url_state],
220
  outputs=[output_area]
221
  )
222
 
223
+ # Clear button
224
  clear_btn.click(
225
  fn=lambda: ("", generate_empty_response()),
226
  outputs=[provider_notes_input, output_area]
227
  )
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
  # Launch
230
  if __name__ == "__main__":
assets/styles.css CHANGED
@@ -377,4 +377,33 @@ html {
377
 
378
  .gradio-container {
379
  overflow: hidden !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  }
 
377
 
378
  .gradio-container {
379
  overflow: hidden !important;
380
+ }
381
+
382
+ /* ==================== Upload Redirect Button ==================== */
383
+ .upload-redirect-button {
384
+ background: linear-gradient(135deg, #ff8c00 0%, #ff6b00 100%) !important;
385
+ color: white !important;
386
+ border: none !important;
387
+ border-radius: 10px !important;
388
+ padding: 14px 20px !important;
389
+ margin: 10px 0 !important;
390
+ font-weight: 600 !important;
391
+ font-size: 1rem !important;
392
+ cursor: pointer !important;
393
+ transition: all 0.3s ease !important;
394
+ width: 100% !important;
395
+ text-align: center !important;
396
+ box-shadow: 0 3px 8px rgba(255, 140, 0, 0.3) !important;
397
+ display: block !important;
398
+ }
399
+
400
+ .upload-redirect-button:hover {
401
+ background: linear-gradient(135deg, #ffa500 0%, #ff8c00 100%) !important;
402
+ transform: translateY(-3px) !important;
403
+ box-shadow: 0 6px 16px rgba(255, 140, 0, 0.5) !important;
404
+ }
405
+
406
+ .upload-redirect-button:active {
407
+ transform: translateY(-1px) !important;
408
+ box-shadow: 0 4px 10px rgba(255, 140, 0, 0.4) !important;
409
  }