Commit ·
a6bf2ce
1
Parent(s): 50f566c
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer from the local directory
|
| 5 |
+
model_path = "disilbart-med-summary" # Replace with the actual path
|
| 6 |
+
tokenizer = BartTokenizer.from_pretrained(model_path)
|
| 7 |
+
model = BartForConditionalGeneration.from_pretrained(model_path)
|
| 8 |
+
|
| 9 |
+
# Function to generate summary based on input
|
| 10 |
+
def generate_summary(input_text):
|
| 11 |
+
# Tokenize the input text
|
| 12 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
# Generate summary
|
| 15 |
+
summary_ids = model.generate(input_ids, max_length=4000, num_beams=4, no_repeat_ngram_size=2)
|
| 16 |
+
|
| 17 |
+
# Decode the summary
|
| 18 |
+
summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 19 |
+
return summary_text
|
| 20 |
+
|
| 21 |
+
# Streamlit app
|
| 22 |
+
def main():
|
| 23 |
+
# Apply custom styling for the title
|
| 24 |
+
st.markdown("<h3 style='text-align: center; color: #333;'>Medical Summary - Text Generation</h3>", unsafe_allow_html=True)
|
| 25 |
+
|
| 26 |
+
# Textbox for user input
|
| 27 |
+
user_input = st.text_area("Enter Text:", "")
|
| 28 |
+
|
| 29 |
+
# Button to trigger text generation
|
| 30 |
+
if st.button("Generate Summary"):
|
| 31 |
+
if user_input:
|
| 32 |
+
# Call the generate_summary function with user input
|
| 33 |
+
result = generate_summary(user_input)
|
| 34 |
+
|
| 35 |
+
# Display the generated summary in a text area with word wrap
|
| 36 |
+
st.text_area("Generated Summary:", result, key="generated_summary")
|
| 37 |
+
|
| 38 |
+
# Run the Streamlit app
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
main()
|