Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -498,15 +498,14 @@ RESPONSE (provide practical, Gaza-appropriate medical guidance):"""
|
|
498 |
max_length=512,
|
499 |
padding="max_length"
|
500 |
)
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
outputs = self.llm.generate(
|
510 |
input_ids=input_ids,
|
511 |
attention_mask=attention_mask,
|
512 |
max_new_tokens=256,
|
@@ -515,27 +514,20 @@ RESPONSE (provide practical, Gaza-appropriate medical guidance):"""
|
|
515 |
do_sample=True,
|
516 |
repetition_penalty=1.15,
|
517 |
no_repeat_ngram_size=3
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
logger.info(f"🧪 Final cleaned response:\n{final_response}")
|
533 |
-
|
534 |
-
return final_response
|
535 |
-
|
536 |
-
except Exception as e:
|
537 |
-
logger.error(f"❌ Error in LLM generate(): {e}")
|
538 |
-
return self._generate_fallback_response(query, context)
|
539 |
|
540 |
|
541 |
|
|
|
498 |
max_length=512,
|
499 |
padding="max_length"
|
500 |
)
|
501 |
+
input_ids = inputs["input_ids"]
|
502 |
+
attention_mask = inputs["attention_mask"]
|
503 |
+
device = self.llm.device if hasattr(self.llm, "device") else "cpu"
|
504 |
+
input_ids = input_ids.to(device)
|
505 |
+
attention_mask = attention_mask.to(device)
|
506 |
+
|
507 |
+
with torch.no_grad():
|
508 |
+
outputs = self.llm.generate(
|
|
|
509 |
input_ids=input_ids,
|
510 |
attention_mask=attention_mask,
|
511 |
max_new_tokens=256,
|
|
|
514 |
do_sample=True,
|
515 |
repetition_penalty=1.15,
|
516 |
no_repeat_ngram_size=3
|
517 |
+
)
|
518 |
+
response_text = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
519 |
+
lines = response_text.split('\n')
|
520 |
+
unique_lines = []
|
521 |
+
for line in lines:
|
522 |
+
line = line.strip()
|
523 |
+
if line and line not in unique_lines and len(line) > 10:
|
524 |
+
unique_lines.append(line)
|
525 |
+
final_response = '\n'.join(unique_lines)
|
526 |
+
logger.info(f"🧪 Final cleaned response:\n{final_response}")
|
527 |
+
return final_response
|
528 |
+
except Exception as e:
|
529 |
+
logger.error(f"❌ Error in LLM generate(): {e}")
|
530 |
+
return self._generate_fallback_response(query, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
|
533 |
|