Spaces:
Runtime error
Runtime error
Commit
·
b5568be
1
Parent(s):
a9a8be4
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,28 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return generated_text
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
gr.Interface(
|
19 |
text_generation,
|
20 |
-
[gr.inputs.Textbox(lines=2, label="Enter
|
21 |
-
[gr.outputs.Textbox(type="auto", label="
|
22 |
title=title,
|
23 |
description=description,
|
24 |
theme="huggingface"
|
|
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
|
4 |
+
from peft import PeftModel, PeftConfig
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer ,pipeline
|
6 |
|
7 |
+
config = PeftConfig.from_pretrained("ShishuTripathi/entity_coder")
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("ybelkada/falcon-7b-sharded-bf16")
|
9 |
+
model = PeftModel.from_pretrained(model, "ShishuTripathi/entity_coder")
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("ShishuTripathi/entity_coder")
|
11 |
+
generator = pipeline('text-generation' , model = model, tokenizer =tokenizer, max_length = 50)
|
|
|
12 |
|
13 |
+
def text_generation(input_text):
|
14 |
+
prompt = f"### Narrative: {input_text} \n ### Reported Term:"
|
15 |
+
out = generator(prompt)
|
16 |
+
output = out[0]['generated_text'].replace('|endoftext|',' ').strip()
|
17 |
+
return output
|
18 |
+
|
19 |
+
title = "Preferred Term Extractor and Coder"
|
20 |
+
description = "The term used to describe an adverse event in the Database of Adverse Event Notifications - medicines is the MedDRA 'preferred term', which describes a single medical concept"
|
21 |
|
22 |
gr.Interface(
|
23 |
text_generation,
|
24 |
+
[gr.inputs.Textbox(lines=2, label="Enter Narrative or Phrase")],
|
25 |
+
[gr.outputs.Textbox(type="auto", label="Extracted Preffered Term")],
|
26 |
title=title,
|
27 |
description=description,
|
28 |
theme="huggingface"
|