Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,96 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 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 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Creating pipeline
|
| 5 |
+
classifier = pipeline("text-classification", model="ARI-HIPA-AI-Team/keras_model")
|
| 6 |
+
classifier(text)
|
| 7 |
+
|
| 8 |
+
text = inputs
|
| 9 |
+
|
| 10 |
+
# Creating a function for text classification
|
| 11 |
+
def text_classification(text):
|
| 12 |
+
result= classifier(text)
|
| 13 |
+
sentiment_label = result[0]['label']
|
| 14 |
+
formatted_output = f"The provided text {sentiment_label} a predicted HIPAA violation."
|
| 15 |
+
return formatted_output
|
| 16 |
+
|
| 17 |
+
# Getting examples
|
| 18 |
+
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."]
|
| 19 |
+
|
| 20 |
+
# Building a Gradio interface
|
| 21 |
+
io = gr.Interface(fn=text_classification,
|
| 22 |
+
inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter text here..."),
|
| 23 |
+
outputs=gr.Textbox(lines=2, label="HIPAA Violation Prediction"),
|
| 24 |
+
title="HIPAA Classifier",
|
| 25 |
+
description="Enter text to see whether it violates HIPAA.",
|
| 26 |
+
examples=examples)
|
| 27 |
+
|
| 28 |
+
io.launch(inline=False, share=True)
|
| 29 |
+
|
| 30 |
+
# import gradio as gr
|
| 31 |
+
# from huggingface_hub import InferenceClient
|
| 32 |
+
# from transformers import pipeline
|
| 33 |
+
|
| 34 |
+
# """
|
| 35 |
+
# 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
|
| 36 |
+
# """
|
| 37 |
+
# model_reference = 'ARI-HIPA-AI-Team/keras_model'
|
| 38 |
+
# classifier = pipeline("text-classification", model='ARI-HIPA-AI-Team/keras_model')
|
| 39 |
+
# classifier
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# def respond(
|
| 43 |
+
# message,
|
| 44 |
+
# history: list[tuple[str, str]],
|
| 45 |
+
# system_message,
|
| 46 |
+
# max_tokens,
|
| 47 |
+
# temperature,
|
| 48 |
+
# top_p,
|
| 49 |
+
# ):
|
| 50 |
+
# messages = [{"role": "system", "content": system_message}]
|
| 51 |
+
|
| 52 |
+
# for val in history:
|
| 53 |
+
# if val[0]:
|
| 54 |
+
# messages.append({"role": "user", "content": val[0]})
|
| 55 |
+
# if val[1]:
|
| 56 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
| 57 |
+
|
| 58 |
+
# messages.append({"role": "user", "content": message})
|
| 59 |
+
|
| 60 |
+
# response = ""
|
| 61 |
+
|
| 62 |
+
# for message in client.chat_completion(
|
| 63 |
+
# messages,
|
| 64 |
+
# max_tokens=max_tokens,
|
| 65 |
+
# stream=True,
|
| 66 |
+
# temperature=temperature,
|
| 67 |
+
# top_p=top_p,
|
| 68 |
+
# ):
|
| 69 |
+
# token = message.choices[0].delta.content
|
| 70 |
+
|
| 71 |
+
# response += token
|
| 72 |
+
# yield response
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# """
|
| 76 |
+
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 77 |
+
# """
|
| 78 |
+
# demo = gr.ChatInterface(
|
| 79 |
+
# respond,
|
| 80 |
+
# additional_inputs=[
|
| 81 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 82 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 83 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 84 |
+
# gr.Slider(
|
| 85 |
+
# minimum=0.1,
|
| 86 |
+
# maximum=1.0,
|
| 87 |
+
# value=0.95,
|
| 88 |
+
# step=0.05,
|
| 89 |
+
# label="Top-p (nucleus sampling)",
|
| 90 |
+
# ),
|
| 91 |
+
# ],
|
| 92 |
+
# )
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# if __name__ == "__main__":
|
| 96 |
+
# demo.launch()
|