File size: 2,281 Bytes
e669abf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82818a6
e669abf
f3760ed
e669abf
 
 
 
 
 
 
 
 
 
d2c6fef
e669abf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82818a6
e669abf
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
import gradio as gr
import torch
import tensorflow as tf
from transformers import RobertaTokenizer, RobertaModel
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/ADRv1")  
model = AutoModelForSequenceClassification.from_pretrained("paragon-analytics/ADRv1")

def adr_predict(x):
    encoded_input = tokenizer(x, return_tensors='pt')
    output = model(**encoded_input)
    scores = output[0][0].detach().numpy()
    scores = tf.nn.softmax(scores)
    return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])} 

def main(text):
    text = str(text).lower()
    obj = adr_predict(text)
    return obj

title = "Welcome to **ADR Detector** πŸͺ"
description1 = """
This app takes text (up to a few sentences) and predicts to what extent the text describes severe (or non-severe) adverse reaction to medicaitons.
"""

with gr.Blocks(title=title) as demo:
    gr.Markdown(f"## {title}")
    gr.Markdown(description1)
    gr.Markdown("""---""")
    text = gr.Textbox(label="Enter Your Text Here:",lines=2, placeholder="Type it here ...")
    submit_btn = gr.Button("Analyze")


    with gr.Column(visible=True) as output_col:
        label = gr.Label(label = "Predicted Label")
        # impplot = gr.HighlightedText(label="Important Words", combine_adjacent=False).style(
        # color_map={"+++": "royalblue","++": "cornflowerblue",
        #  "+": "lightsteelblue", "NA":"white"})
        # NER = gr.HTML(label = 'NER:')
        # intp =gr.HighlightedText(label="Word Scores",
        # combine_adjacent=False).style(color_map={"++": "darkgreen","+": "green", 
        #                                         "--": "darkred",
        #                                         "-": "red", "NA":"white"})

    submit_btn.click(
        main,
        [text],
        [label], api_name="adr"
    )

    gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
    gr.Examples([["I have minor pain."],["I have severe pain."]], [text], [label], main, cache_examples=True)
    
demo.launch()