Wall06 commited on
Commit
3c70ae8
Β·
verified Β·
1 Parent(s): 53470fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -89,9 +89,7 @@ def generate_audio_report(text):
89
  raise gr.Error("❌ No valid report text found. Generate report first!")
90
 
91
  try:
92
- # No API Key needed for gTTS
93
  tts = gTTS(text=text[:1500], lang='en')
94
-
95
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
96
  tts.save(f.name)
97
  return f.name
@@ -166,7 +164,6 @@ def generate_pdf(wqi, hsi, erosion, turbidity, summary_text):
166
  pdf.set_font("Arial", "", 12)
167
  pdf.set_text_color(0, 0, 0)
168
 
169
- # Cleaning summary for FPDF compatibility
170
  clean_text = summary_text.encode('latin-1', 'replace').decode('latin-1')
171
  pdf.multi_cell(0, 6, clean_text)
172
 
@@ -190,7 +187,6 @@ def process_data(flow_rate, water_temp, sediment, construction, pH, do, nutrient
190
  fig = create_plots(wqi, hsi, erosion, turbidity)
191
  graph_text = generate_graph_insights(wqi, hsi, erosion, turbidity)
192
 
193
- # Returns path for gr.File to enable download
194
  pdf_path = generate_pdf(wqi, hsi, erosion, turbidity, summary)
195
 
196
  status_text = f"Stability Index: {stability}/100\nStatus: {potability}"
@@ -199,16 +195,33 @@ def process_data(flow_rate, water_temp, sediment, construction, pH, do, nutrient
199
  except Exception as e:
200
  return str(e), None, "", "", None
201
 
202
- # Wrapper
203
  def run_app(flow, temp, sediment, construction, ph, do, nutrients, sat_img):
204
  return process_data(flow, temp, sediment, construction, ph, do, nutrients, sat_img)
205
 
206
- # -------------------- UI DESIGN --------------------
207
  custom_css = """
208
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
209
  * { font-family: 'Poppins', sans-serif !important; }
210
  #title-box { background: linear-gradient(135deg, #0061ff 0%, #60efff 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;}
211
  #analyze-btn { background: #0061ff; color: white; border: none; font-weight: bold; cursor: pointer; border-radius: 8px;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  """
213
 
214
  with gr.Blocks(title="FlumenIntel") as demo:
@@ -217,10 +230,8 @@ with gr.Blocks(title="FlumenIntel") as demo:
217
  gr.Markdown("# FlumenIntel 🌊\n### Advanced River Health Analytics")
218
 
219
  with gr.Tabs():
220
- # --- TAB 1: DASHBOARD ---
221
  with gr.TabItem("πŸš€ Dashboard"):
222
  with gr.Row():
223
- # LEFT INPUTS
224
  with gr.Column(scale=1):
225
  gr.Markdown("### 1. Hydrological Data")
226
  flow = gr.Number(label="Flow Rate", value=45)
@@ -238,7 +249,6 @@ with gr.Blocks(title="FlumenIntel") as demo:
238
 
239
  analyze_btn = gr.Button("GENERATE REPORT", elem_id="analyze-btn")
240
 
241
- # RIGHT OUTPUTS
242
  with gr.Column(scale=2):
243
  status_box = gr.Textbox(label="System Status", interactive=False)
244
 
@@ -248,9 +258,14 @@ with gr.Blocks(title="FlumenIntel") as demo:
248
  graph_summary_box = gr.Markdown("### Insights...")
249
 
250
  with gr.TabItem("πŸ“„ Official Report"):
251
- ai_summary = gr.Textbox(label="Scientist's Assessment", lines=15, interactive=False)
 
 
 
 
 
 
252
 
253
- # --- AUDIO BUTTON ---
254
  with gr.Row():
255
  audio_btn = gr.Button("πŸ”Š Listen to Report (gTTS)")
256
  audio_out = gr.Audio(label="Player", type="filepath")
@@ -262,14 +277,11 @@ with gr.Blocks(title="FlumenIntel") as demo:
262
  )
263
 
264
  with gr.TabItem("πŸ“₯ Export"):
265
- # The gr.File component provides the download sign automatically
266
  pdf_output = gr.File(label="Download Official FlumenIntel Report")
267
 
268
- # --- TAB 2: ABOUT ME ---
269
  with gr.TabItem("πŸ‘€ About Me"):
270
  gr.Markdown("## Abdullah\nComputer Engineering Undergraduate | AI & Hardware Enthusiast")
271
 
272
- # Events
273
  analyze_btn.click(
274
  run_app,
275
  inputs=[flow, temp, sediment, construction, ph, do, nutrients, sat_img],
 
89
  raise gr.Error("❌ No valid report text found. Generate report first!")
90
 
91
  try:
 
92
  tts = gTTS(text=text[:1500], lang='en')
 
93
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
94
  tts.save(f.name)
95
  return f.name
 
164
  pdf.set_font("Arial", "", 12)
165
  pdf.set_text_color(0, 0, 0)
166
 
 
167
  clean_text = summary_text.encode('latin-1', 'replace').decode('latin-1')
168
  pdf.multi_cell(0, 6, clean_text)
169
 
 
187
  fig = create_plots(wqi, hsi, erosion, turbidity)
188
  graph_text = generate_graph_insights(wqi, hsi, erosion, turbidity)
189
 
 
190
  pdf_path = generate_pdf(wqi, hsi, erosion, turbidity, summary)
191
 
192
  status_text = f"Stability Index: {stability}/100\nStatus: {potability}"
 
195
  except Exception as e:
196
  return str(e), None, "", "", None
197
 
 
198
  def run_app(flow, temp, sediment, construction, ph, do, nutrients, sat_img):
199
  return process_data(flow, temp, sediment, construction, ph, do, nutrients, sat_img)
200
 
201
+ # -------------------- UI DESIGN (WITH SCROLLBAR) --------------------
202
  custom_css = """
203
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
204
  * { font-family: 'Poppins', sans-serif !important; }
205
  #title-box { background: linear-gradient(135deg, #0061ff 0%, #60efff 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;}
206
  #analyze-btn { background: #0061ff; color: white; border: none; font-weight: bold; cursor: pointer; border-radius: 8px;}
207
+
208
+ /* Custom Scroll Wheel for Official Report */
209
+ #scroll-area textarea {
210
+ overflow-y: scroll !important;
211
+ scrollbar-width: thin;
212
+ scrollbar-color: #0061ff #2d2d2d;
213
+ }
214
+ #scroll-area textarea::-webkit-scrollbar {
215
+ width: 8px;
216
+ }
217
+ #scroll-area textarea::-webkit-scrollbar-track {
218
+ background: #1a1a1a;
219
+ }
220
+ #scroll-area textarea::-webkit-scrollbar-thumb {
221
+ background-color: #0061ff;
222
+ border-radius: 10px;
223
+ border: 2px solid #1a1a1a;
224
+ }
225
  """
226
 
227
  with gr.Blocks(title="FlumenIntel") as demo:
 
230
  gr.Markdown("# FlumenIntel 🌊\n### Advanced River Health Analytics")
231
 
232
  with gr.Tabs():
 
233
  with gr.TabItem("πŸš€ Dashboard"):
234
  with gr.Row():
 
235
  with gr.Column(scale=1):
236
  gr.Markdown("### 1. Hydrological Data")
237
  flow = gr.Number(label="Flow Rate", value=45)
 
249
 
250
  analyze_btn = gr.Button("GENERATE REPORT", elem_id="analyze-btn")
251
 
 
252
  with gr.Column(scale=2):
253
  status_box = gr.Textbox(label="System Status", interactive=False)
254
 
 
258
  graph_summary_box = gr.Markdown("### Insights...")
259
 
260
  with gr.TabItem("πŸ“„ Official Report"):
261
+ # Applied elem_id here to link with CSS
262
+ ai_summary = gr.Textbox(
263
+ label="Scientist's Assessment",
264
+ lines=15,
265
+ interactive=False,
266
+ elem_id="scroll-area"
267
+ )
268
 
 
269
  with gr.Row():
270
  audio_btn = gr.Button("πŸ”Š Listen to Report (gTTS)")
271
  audio_out = gr.Audio(label="Player", type="filepath")
 
277
  )
278
 
279
  with gr.TabItem("πŸ“₯ Export"):
 
280
  pdf_output = gr.File(label="Download Official FlumenIntel Report")
281
 
 
282
  with gr.TabItem("πŸ‘€ About Me"):
283
  gr.Markdown("## Abdullah\nComputer Engineering Undergraduate | AI & Hardware Enthusiast")
284
 
 
285
  analyze_btn.click(
286
  run_app,
287
  inputs=[flow, temp, sediment, construction, ph, do, nutrients, sat_img],