SmartHeal commited on
Commit
b87a29c
·
verified ·
1 Parent(s): dedfc66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +407 -56
app.py CHANGED
@@ -1,64 +1,415 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
 
 
 
 
 
 
 
 
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- if __name__ == "__main__":
64
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
 
4
+ HF_TOKEN = os.getenv("HF_TOKEN")
5
+ if not HF_TOKEN:
6
+ raise RuntimeError("HF_TOKEN not found! Add it in Settings → Secrets.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Load private Space securely
9
+ demo = gr.load(
10
+ "spaces/SmartHeal/SmartHeal-Agentic-AI", # Replace with your private Space path
11
+ token=HF_TOKEN
12
+ )
 
 
 
 
 
 
 
 
13
 
14
+ # Define the medical color scheme based on the logo
15
+ primary_color = "#E53E3E" # Red color from the logo
16
+ secondary_color = "#FF6B6B" # Lighter coral
17
+ accent_color = "#FED7D7" # Very light pink/coral
18
+ success_color = "#38A169" # Medical green
19
+ warning_color = "#D69E2E" # Medical amber
20
+ background_color = "#FFFFFF" # White background
21
+ text_color = "#1A202C" # Darker text for better contrast
22
 
23
+ # Aggressive CSS to override Gradio's dark mode and ensure text visibility
24
+ custom_css = """
25
+ /* =================== ORIGINAL SMARTHEAL CSS =================== */
26
+ /* Global Styling */
27
+ body, html {
28
+ margin: 0 !important;
29
+ padding: 0 !important;
30
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif !important;
31
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
32
+ color: #1A202C !important;
33
+ line-height: 1.6 !important;
34
+ }
35
+ /* Professional Header with Logo */
36
+ .medical-header {
37
+ background: linear-gradient(135deg, #3182ce 0%, #2c5aa0 100%) !important;
38
+ color: white !important;
39
+ padding: 32px 40px !important;
40
+ border-radius: 20px 20px 0 0 !important;
41
+ display: flex !important;
42
+ align-items: center !important;
43
+ justify-content: center !important;
44
+ margin-bottom: 0 !important;
45
+ box-shadow: 0 10px 40px rgba(49, 130, 206, 0.3) !important;
46
+ border: none !important;
47
+ position: relative !important;
48
+ overflow: hidden !important;
49
+ }
50
+ .medical-header::before {
51
+ content: '' !important;
52
+ position: absolute !important;
53
+ top: 0 !important;
54
+ left: 0 !important;
55
+ right: 0 !important;
56
+ bottom: 0 !important;
57
+ background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)" /></svg>') !important;
58
+ opacity: 0.1 !important;
59
+ z-index: 1 !important;
60
+ }
61
+ .medical-header > * {
62
+ position: relative !important;
63
+ z-index: 2 !important;
64
+ }
65
+ .logo {
66
+ width: 80px !important;
67
+ height: 80px !important;
68
+ border-radius: 50% !important;
69
+ margin-right: 24px !important;
70
+ border: 4px solid rgba(255, 255, 255, 0.3) !important;
71
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2) !important;
72
+ background: white !important;
73
+ padding: 4px !important;
74
+ }
75
+ .medical-header h1 {
76
+ font-size: 3.5rem !important;
77
+ font-weight: 800 !important;
78
+ margin: 0 !important;
79
+ text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3) !important;
80
+ background: linear-gradient(45deg, #ffffff, #f8f9fa) !important;
81
+ -webkit-background-clip: text !important;
82
+ -webkit-text-fill-color: transparent !important;
83
+ background-clip: text !important;
84
+ filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3)) !important;
85
+ }
86
+ .medical-header p {
87
+ font-size: 1.3rem !important;
88
+ margin: 8px 0 0 0 !important;
89
+ opacity: 0.95 !important;
90
+ font-weight: 500 !important;
91
+ text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2) !important;
92
+ }
93
+ /* Enhanced Form Styling */
94
+ .gr-form {
95
+ background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%) !important;
96
+ border-radius: 20px !important;
97
+ padding: 32px !important;
98
+ margin: 24px 0 !important;
99
+ box-shadow: 0 16px 48px rgba(0, 0, 0, 0.1) !important;
100
+ border: 1px solid rgba(229, 62, 62, 0.1) !important;
101
+ backdrop-filter: blur(10px) !important;
102
+ position: relative !important;
103
+ overflow: hidden !important;
104
+ }
105
+ .gr-form::before {
106
+ content: '' !important;
107
+ position: absolute !important;
108
+ top: 0 !important;
109
+ left: 0 !important;
110
+ right: 0 !important;
111
+ height: 4px !important;
112
+ background: linear-gradient(90deg, #e53e3e 0%, #f56565 50%, #e53e3e 100%) !important;
113
+ z-index: 1 !important;
114
+ }
115
+ /* Professional Input Fields */
116
+ .gr-textbox, .gr-number {
117
+ border-radius: 12px !important;
118
+ border: 2px solid #E2E8F0 !important;
119
+ background: #FFFFFF !important;
120
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
121
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
122
+ font-size: 1rem !important;
123
+ color: #1A202C !important;
124
+ padding: 16px 20px !important;
125
+ }
126
+ .gr-textbox:focus,
127
+ .gr-number:focus,
128
+ .gr-textbox input:focus,
129
+ .gr-number input:focus {
130
+ border-color: #E53E3E !important;
131
+ box-shadow: 0 0 0 4px rgba(229, 62, 62, 0.1) !important;
132
+ background: #FFFFFF !important;
133
+ outline: none !important;
134
+ transform: translateY(-1px) !important;
135
+ }
136
+ .gr-textbox input,
137
+ .gr-number input {
138
+ background: transparent !important;
139
+ border: none !important;
140
+ outline: none !important;
141
+ color: #1A202C !important;
142
+ font-size: 1rem !important;
143
+ width: 100% !important;
144
+ padding: 0 !important;
145
+ }
146
+ .gr-textbox label,
147
+ .gr-number label,
148
+ .gr-dropdown label,
149
+ .gr-radio label,
150
+ .gr-checkbox label {
151
+ font-weight: 600 !important;
152
+ color: #2D3748 !important;
153
+ font-size: 1rem !important;
154
+ margin-bottom: 8px !important;
155
+ display: block !important;
156
+ }
157
+ /* Enhanced Button Styling */
158
+ button.gr-button,
159
+ button.gr-button-primary {
160
+ background: linear-gradient(135deg, #E53E3E 0%, #C53030 100%) !important;
161
+ color: #FFFFFF !important;
162
+ border: none !important;
163
+ border-radius: 12px !important;
164
+ font-weight: 700 !important;
165
+ padding: 16px 32px !important;
166
+ font-size: 1.1rem !important;
167
+ letter-spacing: 0.5px !important;
168
+ text-align: center !important;
169
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
170
+ box-shadow: 0 4px 16px rgba(229, 62, 62, 0.3) !important;
171
+ position: relative !important;
172
+ overflow: hidden !important;
173
+ text-transform: uppercase !important;
174
+ cursor: pointer !important;
175
+ }
176
+ button.gr-button::before {
177
+ content: '' !important;
178
+ position: absolute !important;
179
+ top: 0 !important;
180
+ left: -100% !important;
181
+ width: 100% !important;
182
+ height: 100% !important;
183
+ background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent) !important;
184
+ transition: left 0.5s !important;
185
+ }
186
+ button.gr-button:hover::before {
187
+ left: 100% !important;
188
+ }
189
+ button.gr-button:hover,
190
+ button.gr-button-primary:hover {
191
+ background: linear-gradient(135deg, #C53030 0%, #9C2A2A 100%) !important;
192
+ box-shadow: 0 8px 32px rgba(229, 62, 62, 0.4) !important;
193
+ transform: translateY(-3px) !important;
194
+ }
195
+ button.gr-button:active,
196
+ button.gr-button-primary:active {
197
+ transform: translateY(-1px) !important;
198
+ box-shadow: 0 4px 16px rgba(229, 62, 62, 0.5) !important;
199
+ }
200
+ button.gr-button:disabled {
201
+ background: #A0AEC0 !important;
202
+ color: #718096 !important;
203
+ cursor: not-allowed !important;
204
+ box-shadow: none !important;
205
+ transform: none !important;
206
+ }
207
+ /* Professional Status Messages */
208
+ .status-success {
209
+ background: linear-gradient(135deg, #F0FFF4 0%, #E6FFFA 100%) !important;
210
+ border: 2px solid #38A169 !important;
211
+ color: #22543D !important;
212
+ padding: 20px 24px !important;
213
+ border-radius: 16px !important;
214
+ font-weight: 600 !important;
215
+ margin: 16px 0 !important;
216
+ box-shadow: 0 8px 24px rgba(56, 161, 105, 0.2) !important;
217
+ backdrop-filter: blur(10px) !important;
218
+ }
219
+ .status-error {
220
+ background: linear-gradient(135deg, #FFF5F5 0%, #FED7D7 100%) !important;
221
+ border: 2px solid #E53E3E !important;
222
+ color: #742A2A !important;
223
+ padding: 20px 24px !important;
224
+ border-radius: 16px !important;
225
+ font-weight: 600 !important;
226
+ margin: 16px 0 !important;
227
+ box-shadow: 0 8px 24px rgba(229, 62, 62, 0.2) !important;
228
+ backdrop-filter: blur(10px) !important;
229
+ }
230
+ .status-warning {
231
+ background: linear-gradient(135deg, #FFFAF0 0%, #FEEBC8 100%) !important;
232
+ border: 2px solid #DD6B20 !important;
233
+ color: #9C4221 !important;
234
+ padding: 20px 24px !important;
235
+ border-radius: 16px !important;
236
+ font-weight: 600 !important;
237
+ margin: 16px 0 !important;
238
+ box-shadow: 0 8px 24px rgba(221, 107, 32, 0.2) !important;
239
+ backdrop-filter: blur(10px) !important;
240
+ }
241
+ /* Professional Card Layout */
242
+ .medical-card {
243
+ background: linear-gradient(145deg, #FFFFFF 0%, #F7FAFC 100%) !important;
244
+ border-radius: 20px !important;
245
+ padding: 32px !important;
246
+ margin: 24px 0 !important;
247
+ box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08) !important;
248
+ border: 1px solid rgba(229, 62, 62, 0.1) !important;
249
+ backdrop-filter: blur(10px) !important;
250
+ position: relative !important;
251
+ overflow: hidden !important;
252
+ }
253
+ .medical-card::before {
254
+ content: '' !important;
255
+ position: absolute !important;
256
+ top: 0 !important;
257
+ left: 0 !important;
258
+ right: 0 !important;
259
+ height: 4px !important;
260
+ background: linear-gradient(90deg, #E53E3E 0%, #F56565 50%, #E53E3E 100%) !important;
261
+ }
262
+ .medical-card-title {
263
+ font-size: 1.75rem !important;
264
+ font-weight: 700 !important;
265
+ color: #1A202C !important;
266
+ margin-bottom: 24px !important;
267
+ padding-bottom: 16px !important;
268
+ border-bottom: 2px solid #E53E3E !important;
269
+ text-align: center !important;
270
+ position: relative !important;
271
+ }
272
+ .medical-card-title::after {
273
+ content: '' !important;
274
+ position: absolute !important;
275
+ bottom: -2px !important;
276
+ left: 50% !important;
277
+ transform: translateX(-50%) !important;
278
+ width: 60px !important;
279
+ height: 4px !important;
280
+ background: linear-gradient(90deg, transparent, #E53E3E, transparent) !important;
281
+ border-radius: 2px !important;
282
+ }
283
+ /* Professional Dropdown Styling */
284
+ .gr-dropdown {
285
+ border-radius: 12px !important;
286
+ border: 2px solid #E2E8F0 !important;
287
+ background: #FFFFFF !important;
288
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
289
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
290
+ }
291
+ .gr-dropdown:focus,
292
+ .gr-dropdown select:focus {
293
+ border-color: #E53E3E !important;
294
+ box-shadow: 0 0 0 4px rgba(229, 62, 62, 0.1) !important;
295
+ outline: none !important;
296
+ }
297
+ .gr-dropdown select {
298
+ background: transparent !important;
299
+ border: none !important;
300
+ color: #1A202C !important;
301
+ font-size: 1rem !important;
302
+ padding: 16px 20px !important;
303
+ border-radius: 12px !important;
304
+ }
305
+ /* Radio button styling */
306
+ .gr-radio input[type="radio"] {
307
+ margin-right: 8px !important;
308
+ transform: scale(1.2) !important;
309
+ }
310
+ .gr-radio label {
311
+ display: flex !important;
312
+ align-items: center !important;
313
+ padding: 8px 0 !important;
314
+ font-size: 1rem !important;
315
+ line-height: 1.5 !important;
316
+ cursor: pointer !important;
317
+ color: #1A202C !important;
318
+ }
319
+ /* Tab styling */
320
+ .gr-tab {
321
+ color: #1A202C !important;
322
+ font-weight: 500 !important;
323
+ font-size: 1rem !important;
324
+ padding: 12px 20px !important;
325
+ background-color: #F7FAFC !important;
326
+ }
327
+ .gr-tab.selected {
328
+ color: #E53E3E !important;
329
+ font-weight: 600 !important;
330
+ border-bottom: 2px solid #E53E3E !important;
331
+ background-color: #FFFFFF !important;
332
+ }
333
+ /* Image upload styling */
334
+ .gr-image {
335
+ border: 3px dashed #CBD5E0 !important;
336
+ border-radius: 16px !important;
337
+ background-color: #F7FAFC !important;
338
+ transition: all 0.2s ease !important;
339
+ }
340
+ .gr-image:hover {
341
+ border-color: #E53E3E !important;
342
+ background-color: #FFF5F5 !important;
343
+ }
344
+ /* Analyze button special styling */
345
+ #analyze-btn {
346
+ background: linear-gradient(135deg, #1B5CF3 0%, #1E3A8A 100%) !important;
347
+ color: #FFFFFF !important;
348
+ border: none !important;
349
+ border-radius: 8px !important;
350
+ font-weight: 700 !important;
351
+ padding: 14px 28px !important;
352
+ font-size: 1.1rem !important;
353
+ letter-spacing: 0.5px !important;
354
+ text-align: center !important;
355
+ transition: all 0.2s ease-in-out !important;
356
+ }
357
+ #analyze-btn:hover {
358
+ background: linear-gradient(135deg, #174ea6 0%, #123b82 100%) !important;
359
+ box-shadow: 0 4px 14px rgba(27, 95, 193, 0.4) !important;
360
+ transform: translateY(-2px) !important;
361
+ }
362
+ #analyze-btn:disabled {
363
+ background: #A0AEC0 !important;
364
+ color: #1A202C !important;
365
+ cursor: not-allowed !important;
366
+ box-shadow: none !important;
367
+ transform: none !important;
368
+ }
369
+ /* Responsive design */
370
+ @media (max-width: 768px) {
371
+ .medical-header {
372
+ padding: 16px !important;
373
+ text-align: center !important;
374
+ }
375
+
376
+ .medical-header h1 {
377
+ font-size: 2rem !important;
378
+ }
379
+
380
+ .logo {
381
+ width: 48px !important;
382
+ height: 48px !important;
383
+ margin-right: 16px !important;
384
+ }
385
+
386
+ .gr-form {
387
+ padding: 16px !important;
388
+ margin: 8px 0 !important;
389
+ }
390
+
391
+ button.gr-button,
392
+ button.gr-button-primary {
393
+ padding: 14px 20px !important;
394
+ font-size: 14px !important;
395
+ }
396
+ }
397
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
 
399
+ with gr.Blocks(css=custom_css , title="SmartHeal: AI Wound Care Assistant") as app:
400
+ # JS to remove HF embed header
401
+ gr.HTML("""
402
+ <script>
403
+ if (window.location.href.includes("embed=true")) {
404
+ window.location.href = window.location.href.replace("embed=true", "embed=false");
405
+ }
406
+ </script>
407
+ """)
408
+
409
+ # Render your private Space UI
410
+ demo.render()
411
+
412
+ app.launch(
413
+ favicon_path="favicon.ico"
414
+ )
415