Interface / app.py
BraydenAC's picture
Import transformers
2cdb242 verified
raw
history blame
4.73 kB
import gradio as gr
import transformers
from transformers import pipeline
# Creating pipeline
classifier = pipeline("text-classification", model="ARI-HIPA-AI-Team/keras_model")
classifier(text)
text = inputs
# Creating a function for text classification
def text_classification(text):
result= classifier(text)
sentiment_label = result[0]['label']
formatted_output = f"The provided text {sentiment_label} a predicted HIPAA violation."
return formatted_output
# Getting examples
examples=["Has your gestalt been rigorously tested for validity and reliability? I feel like I want to hire some patient actors to check you out, because if medicine can replicate your gestalt nobody will ever have to wonder who is really in pain.", "If it's 7:30 and you have 3 patients you still need to get report on, and you are having a whole tea spill sesh with the secretaries, don't throw a fit when you are called out on it by the very tired off going nurse. Thank you for coming to my TED talk.", "I'm not sure. I haven't witnessed any as a nurse. Before I became a nurse, I was patient. And then, as a nurse, I had an adenomyosis. My doctor was not aware that I was a nurse. My experience with a female doctor was a nightmare; months and months of being tormented with pain around my menstrual cycle. I wasn't sure why she was this way. She was my OBGYN who didn't want to prescribe me contraception but would instead order narcotic medication I didn't like. I explained to her I could not have this medication based on my experience with its side effects. I don't like being drowsy and would get stomach pain. I'm not too fond of the feeling of it. Anyway, she sent me for a vaginal ultrasound to find the source of my pelvic pain. It was normal. She stopped here. I asked for the pill. She declined to renew it after 12-month of supply. I felt a lot better with this, so I stuck with it. I found a male OBGYN. He diagnosed me with adenomyosis. It was a tiny part of my uterus that got affected. It hurt like hell. The doctor told me that if contraception didn't work, surgery would be the last choice if I wanted to get rid of the pain. My life has been great since I started taking pills regularly. I don't miss darn periods and certainly do not forget my pill. The pain was unbearable."]
# Building a Gradio interface
io = gr.Interface(fn=text_classification,
inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter text here..."),
outputs=gr.Textbox(lines=2, label="HIPAA Violation Prediction"),
title="HIPAA Classifier",
description="Enter text to see whether it violates HIPAA.",
examples=examples)
io.launch(inline=False, share=True)
# import gradio as gr
# from huggingface_hub import InferenceClient
# from transformers import pipeline
# """
# For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
# """
# model_reference = 'ARI-HIPA-AI-Team/keras_model'
# classifier = pipeline("text-classification", model='ARI-HIPA-AI-Team/keras_model')
# classifier
# def respond(
# message,
# history: list[tuple[str, str]],
# system_message,
# max_tokens,
# temperature,
# top_p,
# ):
# messages = [{"role": "system", "content": system_message}]
# for val in history:
# if val[0]:
# messages.append({"role": "user", "content": val[0]})
# if val[1]:
# messages.append({"role": "assistant", "content": val[1]})
# messages.append({"role": "user", "content": message})
# response = ""
# for message in client.chat_completion(
# messages,
# max_tokens=max_tokens,
# stream=True,
# temperature=temperature,
# top_p=top_p,
# ):
# token = message.choices[0].delta.content
# response += token
# yield response
# """
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
# """
# demo = gr.ChatInterface(
# respond,
# additional_inputs=[
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
# gr.Slider(
# minimum=0.1,
# maximum=1.0,
# value=0.95,
# step=0.05,
# label="Top-p (nucleus sampling)",
# ),
# ],
# )
# if __name__ == "__main__":
# demo.launch()