Spaces:
Build error
Build error
File size: 1,824 Bytes
ada12e7 f3fae6b bae08e9 ada12e7 86233be ada12e7 86233be ada12e7 |
1 2 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 |
import streamlit as st
import numpy as np
import tensorflow as tf
# from tensorflow.keras.preprocessing.text import Tokenizer
# from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import load_model
import pickle
import joblib
# Load model and tokenizer
model = load_model('rnn_lstm_final.h5')
loaded_model = joblib.load("my_rnn_model.joblib")
with open("tokenizer_and_sequences.pkl", "rb") as f:
tokenizer, data = pickle.load(f)
# Define helper functions
def is_valid_punjabi_text(text):
english_alphabet = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
numbers = set("0123456789")
punctuation = set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
for char in text:
if char in english_alphabet or char in numbers or char in punctuation:
return False
return True
def process_input(text):
a = [text]
a = tokenizer.texts_to_sequences(a)
a = np.array(a)
a = pad_sequences(a, padding='post', maxlen=100)
a = a.reshape((a.shape[0], a.shape[1], 1))
prediction = model.predict(np.array(a))
for row in prediction:
element1 = row[0]
element2 = row[1]
return "Negative" if element1 > element2 else "Positive"
# Streamlit app
st.title("Indic Sentence Summarization & Sentiment Analysis")
st.header("Insightful Echoes: Crafting Summaries with Sentiments (for ਪੰਜਾਬੀ Text)")
summarize_before_sentiment = st.checkbox("Summarize before analyzing sentiment")
user_input = st.text_area("Enter some text here")
if st.button("Analyze Sentiment"):
if not is_valid_punjabi_text(user_input):
st.warning("Please enter valid Punjabi text.")
else:
sentiment_output = process_input(user_input)
st.text_area("Sentiment Output", sentiment_output, height=200)
|