will.k
commited on
Commit
•
80a2449
1
Parent(s):
70ba04d
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from transformers import pipeline, AutoConfig, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, MistralForCausalLM
|
4 |
from peft import PeftModel, PeftConfig
|
|
|
5 |
gr.Blocks(theme= 'pseudolab/huggingface-korea-theme')
|
6 |
|
7 |
#Note this should be used always in compliance with applicable laws and regulations if used with real patient data.
|
@@ -34,14 +35,14 @@ def prepare_context(data):
|
|
34 |
|
35 |
return input_ids
|
36 |
|
37 |
-
|
38 |
data = pd.read_csv(uploaded_file)
|
39 |
-
|
40 |
|
41 |
# Generate text based on the context
|
42 |
context = prepare_context(data)
|
43 |
generated_text = pipeline('text-generation', model=model)(context)[0]['generated_text']
|
44 |
-
|
45 |
|
46 |
# Internally prompt the model to data analyze the EHR patient data
|
47 |
prompt = "You are an Electronic Health Records analyst with nursing school training. Please analyze patient data that you are provided here. Give an organized, step-by-step, formatted health records analysis. You will always be truthful and if you do nont know the answer say you do not know."
|
@@ -52,9 +53,13 @@ if uploaded_file is not None:
|
|
52 |
|
53 |
# Generate text based on the prompt
|
54 |
generated_text = pipeline('text-generation', model=model)(input_ids=input_ids)[0]['generated_text']
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
from transformers import pipeline, AutoConfig, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, MistralForCausalLM
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
+
import gradio as gr
|
6 |
gr.Blocks(theme= 'pseudolab/huggingface-korea-theme')
|
7 |
|
8 |
#Note this should be used always in compliance with applicable laws and regulations if used with real patient data.
|
|
|
35 |
|
36 |
return input_ids
|
37 |
|
38 |
+
def fn(uploaded_file) -> str:
|
39 |
data = pd.read_csv(uploaded_file)
|
40 |
+
ret = ""
|
41 |
|
42 |
# Generate text based on the context
|
43 |
context = prepare_context(data)
|
44 |
generated_text = pipeline('text-generation', model=model)(context)[0]['generated_text']
|
45 |
+
ret += generated_text
|
46 |
|
47 |
# Internally prompt the model to data analyze the EHR patient data
|
48 |
prompt = "You are an Electronic Health Records analyst with nursing school training. Please analyze patient data that you are provided here. Give an organized, step-by-step, formatted health records analysis. You will always be truthful and if you do nont know the answer say you do not know."
|
|
|
53 |
|
54 |
# Generate text based on the prompt
|
55 |
generated_text = pipeline('text-generation', model=model)(input_ids=input_ids)[0]['generated_text']
|
56 |
+
ret += generated_text
|
57 |
+
|
58 |
+
return ret
|
59 |
+
|
60 |
+
|
61 |
+
demo = gr.Interface(fn=fn, inputs="file", outputs="text")
|
62 |
+
|
63 |
+
|
64 |
+
if __name__ == "__main__":
|
65 |
+
demo.launch(show_api=False)
|