Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,12 +22,24 @@ print("Attaching LoRA adapter...")
|
|
| 22 |
model = PeftModel.from_pretrained(base_model, "StudioIlios/icd10-model", token=hf_token)
|
| 23 |
print("Model loaded successfully!")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def predict(clinical_text):
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
with torch.no_grad():
|
| 28 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
|
|
|
| 29 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=predict,
|
|
|
|
| 22 |
model = PeftModel.from_pretrained(base_model, "StudioIlios/icd10-model", token=hf_token)
|
| 23 |
print("Model loaded successfully!")
|
| 24 |
|
| 25 |
+
# def predict(clinical_text):
|
| 26 |
+
# inputs = tokenizer(clinical_text, return_tensors="pt")
|
| 27 |
+
# with torch.no_grad():
|
| 28 |
+
# outputs = model.generate(**inputs, max_new_tokens=30, temperature=0.1)
|
| 29 |
+
# response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
+
# return response.replace(clinical_text, "").strip()
|
| 31 |
+
|
| 32 |
def predict(clinical_text):
|
| 33 |
+
formatted_prompt = f"### Instruction:\nAnalyze the following clinical text and provide the correct ICD-10 code.\n\n### Input:\n{clinical_text}\n\n### Response:\n"
|
| 34 |
+
|
| 35 |
+
inputs = tokenizer(formatted_prompt, return_tensors="pt")
|
| 36 |
+
|
| 37 |
with torch.no_grad():
|
| 38 |
+
outputs = model.generate(**inputs, max_new_tokens=100, temperature=0.1)
|
| 39 |
+
|
| 40 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 41 |
+
final_answer = response.replace(formatted_prompt, "").strip()
|
| 42 |
+
return final_answer
|
| 43 |
|
| 44 |
demo = gr.Interface(
|
| 45 |
fn=predict,
|