richardorama
commited on
Commit
•
4dd480b
1
Parent(s):
ae62e8e
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,44 @@ import ast
|
|
10 |
|
11 |
st.title("Assorted Language Tools - AI Craze")
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
################ STATEMENT SUMMARIZATION #################
|
15 |
|
16 |
# Load the summarization model
|
|
|
10 |
|
11 |
st.title("Assorted Language Tools - AI Craze")
|
12 |
|
13 |
+
|
14 |
+
|
15 |
+
##########################################################
|
16 |
+
|
17 |
+
|
18 |
+
import streamlit as st
|
19 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
20 |
+
|
21 |
+
# Load the LLaMA summarization model and tokenizer
|
22 |
+
MODEL_NAME = "pszemraj/llama-7b-summarization" # Example of a LLaMA model fine-tuned for summarization
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
24 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
25 |
+
|
26 |
+
# Streamlit UI for input
|
27 |
+
st.title("Text Summarization with LLaMA")
|
28 |
+
|
29 |
+
# Input text area for the article
|
30 |
+
article = st.text_area("Enter the text you want to summarize", height=300)
|
31 |
+
|
32 |
+
# Summarize button
|
33 |
+
if st.button("Summarize"):
|
34 |
+
if article:
|
35 |
+
# Tokenize input article
|
36 |
+
inputs = tokenizer(article, return_tensors="pt", truncation=True, padding="longest", max_length=1024)
|
37 |
+
|
38 |
+
# Generate summary
|
39 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
40 |
+
|
41 |
+
# Decode summary
|
42 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
43 |
+
|
44 |
+
# Display the summary
|
45 |
+
st.write("**Summary:**")
|
46 |
+
st.write(summary)
|
47 |
+
else:
|
48 |
+
st.warning("Please enter some text to summarize!")
|
49 |
+
|
50 |
+
|
51 |
################ STATEMENT SUMMARIZATION #################
|
52 |
|
53 |
# Load the summarization model
|