Wh1plashR commited on
Commit
a913fd7
·
verified ·
1 Parent(s): ab69ad0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -31,7 +31,7 @@ You are an energy‑saving expert tasked to help households reduce their monthly
31
  Analyze the following appliance usage data, which is provided in the format "Appliance Name: Wattage, hours/day, days/week".
32
  1. Flag the highest energy consumers.
33
  2. Recommend practical, empathetic, achievable actions.
34
- 3. Suggest appliance swaps (e.g. LED, inverter AC) and habit changes.
35
  Provide at most 5 recommendation bullet points and stop there.
36
  Input Data:
37
  """
@@ -42,22 +42,19 @@ def generate_recommendation(appliance_info: str) -> str:
42
  with torch.no_grad():
43
  outputs = model.generate(
44
  **inputs,
45
- max_new_tokens=100,
46
  use_cache=True,
47
  do_sample=False,
48
  temperature=0.0
49
  )
50
- text = tokenizer.decode(outputs[0], skip_special_tokens=True)
51
- recommendation = text.split("Recommendations:")[-1].strip()
52
-
53
-
54
- if "Note:" in recommendation:
55
-
56
- recommendation = recommendation.split("Note:")[0].strip()
57
-
58
- cleaned_recommendation = "\n".join(line.strip() for line in recommendation.splitlines() if line.strip())
59
-
60
- return cleaned_recommendation
61
 
62
  # Define the Gradio interface
63
  iface = gr.Interface(
 
31
  Analyze the following appliance usage data, which is provided in the format "Appliance Name: Wattage, hours/day, days/week".
32
  1. Flag the highest energy consumers.
33
  2. Recommend practical, empathetic, achievable actions.
34
+ 3. Suggest appliance swaps (e.g. Incandescent to LED, inverter AC) and habit changes.
35
  Provide at most 5 recommendation bullet points and stop there.
36
  Input Data:
37
  """
 
42
  with torch.no_grad():
43
  outputs = model.generate(
44
  **inputs,
45
+ max_new_tokens=120,
46
  use_cache=True,
47
  do_sample=False,
48
  temperature=0.0
49
  )
50
+ text = tokenizer.decode(outputs[0], skip_special_tokens=True)
51
+ # Extract only the part after "Recommendations:"
52
+ recommendation = text.split("Recommendations:")[-1].strip()
53
+ # Keep only the first 5 numbered lines
54
+ lines = recommendation.splitlines()
55
+ filtered_lines = [line for line in lines if line.strip() and line.strip()[0].isdigit()][:5]
56
+ return "\n".join(filtered_lines)
57
+
 
 
 
58
 
59
  # Define the Gradio interface
60
  iface = gr.Interface(