subhoshripal commited on
Commit
0ccb0a5
·
verified ·
1 Parent(s): 5a5dffa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -17
app.py CHANGED
@@ -13,19 +13,36 @@ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
13
  def format_output(text):
14
  impact, business, action = "N/A", "N/A", "N/A"
15
 
16
- try:
17
- lines = text.split("\n")
18
 
19
- for line in lines:
20
- if "Impact Level" in line:
21
- impact = line.split(":")[-1].strip()
22
- elif "Business Translation" in line:
23
- business = line.split(":", 1)[-1].strip()
24
- elif "Strategic Action" in line:
25
- action = line.split(":", 1)[-1].strip()
26
 
27
- except:
28
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  return impact, business, action
31
 
@@ -51,12 +68,13 @@ Log:
51
 
52
  with torch.no_grad():
53
  outputs = model.generate(
54
- **inputs,
55
- max_new_tokens=120,
56
- temperature=0.3,
57
- top_p=0.9,
58
- do_sample=True
59
- )
 
60
 
61
  result = tokenizer.decode(
62
  outputs[0][inputs["input_ids"].shape[-1]:],
 
13
  def format_output(text):
14
  impact, business, action = "N/A", "N/A", "N/A"
15
 
16
+ text = text.lower()
 
17
 
18
+ # Try to extract sections flexibly
19
+ if "impact" in text:
20
+ try:
21
+ impact = text.split("impact")[1].split("\n")[0].replace("level", "").replace(":", "").strip().title()
22
+ except:
23
+ pass
 
24
 
25
+ if "business" in text:
26
+ try:
27
+ business = text.split("business")[1].split("strategic")[0].replace("translation", "").replace(":", "").strip().capitalize()
28
+ except:
29
+ pass
30
+
31
+ if "strategic" in text or "action" in text:
32
+ try:
33
+ action = text.split("strategic")[-1].replace("action", "").replace(":", "").strip().capitalize()
34
+ except:
35
+ pass
36
+
37
+ # FALLBACK: if parsing failed → use whole text smartly
38
+ if business == "N/A":
39
+ business = text[:120].capitalize()
40
+
41
+ if action == "N/A":
42
+ action = "Investigate the issue and apply appropriate fixes."
43
+
44
+ if impact == "N/A":
45
+ impact = "Moderate"
46
 
47
  return impact, business, action
48
 
 
68
 
69
  with torch.no_grad():
70
  outputs = model.generate(
71
+ **inputs,
72
+ max_new_tokens=100,
73
+ temperature=0.2, # more stable
74
+ top_p=0.9,
75
+ do_sample=True,
76
+ repetition_penalty=1.3
77
+ )
78
 
79
  result = tokenizer.decode(
80
  outputs[0][inputs["input_ids"].shape[-1]:],