Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 17 |
-
lines = text.split("\n")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
action = line.split(":", 1)[-1].strip()
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
return impact, business, action
|
| 31 |
|
|
@@ -51,12 +68,13 @@ Log:
|
|
| 51 |
|
| 52 |
with torch.no_grad():
|
| 53 |
outputs = model.generate(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 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]:],
|