geethareddy commited on
Commit
742ffe1
Β·
verified Β·
1 Parent(s): e2e5bfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -9,17 +9,17 @@ from dotenv import load_dotenv
9
  from fpdf import FPDF
10
  import shutil
11
  import html
 
 
12
 
13
  # Load environment variables
14
  load_dotenv()
15
 
16
- # Required env vars check
17
  required_env_vars = ['SF_USERNAME', 'SF_PASSWORD', 'SF_SECURITY_TOKEN']
18
  missing_vars = [var for var in required_env_vars if not os.getenv(var)]
19
  if missing_vars:
20
  raise EnvironmentError(f"Missing required environment variables: {missing_vars}")
21
 
22
- # Load model and tokenizer
23
  model_name = "distilgpt2"
24
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
25
  model = AutoModelForCausalLM.from_pretrained(model_name, low_cpu_mem_usage=True)
@@ -196,6 +196,18 @@ def get_dashboard_data_from_salesforce(supervisor_name, project_id):
196
  except Exception as e:
197
  return f"Error loading dashboard: {e}", "", "", ""
198
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
200
  if not all([role, supervisor_name, project_id, milestones, reflection]):
201
  return "❗ Please fill all fields.", "", None, ""
@@ -287,6 +299,9 @@ def create_interface():
287
  def show_dashboard_html(sup_name, proj_id):
288
  checklist, suggestions, link, date = get_dashboard_data_from_salesforce(sup_name, proj_id)
289
  link_html = f'<a href="{link}" target="_blank">Download PDF</a>' if link else "No report available"
 
 
 
290
  html_card = f"""
291
  <div style='border:1px solid #ccc; border-radius:10px; padding:20px; background-color:#f9f9f9'>
292
  <h3>πŸ“‹ <u>Dashboard Summary</u></h3>
@@ -299,6 +314,9 @@ def create_interface():
299
  <h4>πŸ’‘ <u>Focus Suggestions</u></h4>
300
  <pre style='background:#ffe; padding:10px; border-radius:5px;'>{suggestions}</pre>
301
  <p>{link_html}</p>
 
 
 
302
  </div>
303
  """
304
  return html_card
 
9
  from fpdf import FPDF
10
  import shutil
11
  import html
12
+ import matplotlib.pyplot as plt
13
+ import io
14
 
15
  # Load environment variables
16
  load_dotenv()
17
 
 
18
  required_env_vars = ['SF_USERNAME', 'SF_PASSWORD', 'SF_SECURITY_TOKEN']
19
  missing_vars = [var for var in required_env_vars if not os.getenv(var)]
20
  if missing_vars:
21
  raise EnvironmentError(f"Missing required environment variables: {missing_vars}")
22
 
 
23
  model_name = "distilgpt2"
24
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
25
  model = AutoModelForCausalLM.from_pretrained(model_name, low_cpu_mem_usage=True)
 
196
  except Exception as e:
197
  return f"Error loading dashboard: {e}", "", "", ""
198
 
199
+ def render_bar_chart(completed, total):
200
+ fig, ax = plt.subplots(figsize=(4, 3))
201
+ ax.bar(["Completed", "Remaining"], [completed, max(0, total - completed)], color=["green", "gray"])
202
+ ax.set_title("Checklist Progress")
203
+ buf = io.BytesIO()
204
+ plt.tight_layout()
205
+ fig.savefig(buf, format="png")
206
+ plt.close(fig)
207
+ buf.seek(0)
208
+ encoded = base64.b64encode(buf.read()).decode("utf-8")
209
+ return f"<img src='data:image/png;base64,{encoded}'/>"
210
+
211
  def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
212
  if not all([role, supervisor_name, project_id, milestones, reflection]):
213
  return "❗ Please fill all fields.", "", None, ""
 
299
  def show_dashboard_html(sup_name, proj_id):
300
  checklist, suggestions, link, date = get_dashboard_data_from_salesforce(sup_name, proj_id)
301
  link_html = f'<a href="{link}" target="_blank">Download PDF</a>' if link else "No report available"
302
+ completed_tasks = checklist.count("- ")
303
+ total_tasks = 5
304
+ chart_html = render_bar_chart(completed_tasks, total_tasks)
305
  html_card = f"""
306
  <div style='border:1px solid #ccc; border-radius:10px; padding:20px; background-color:#f9f9f9'>
307
  <h3>πŸ“‹ <u>Dashboard Summary</u></h3>
 
314
  <h4>πŸ’‘ <u>Focus Suggestions</u></h4>
315
  <pre style='background:#ffe; padding:10px; border-radius:5px;'>{suggestions}</pre>
316
  <p>{link_html}</p>
317
+ <hr>
318
+ <h4>πŸ“Š <u>Progress Chart</u></h4>
319
+ {chart_html}
320
  </div>
321
  """
322
  return html_card