Topic-modeling / app.py
awacke1's picture
Update app.py
ba0814f
import streamlit as st
import transformers
import numpy as np
# Load the pre-trained model
model1 = transformers.pipeline("text2text-generation", model="bigscience/T0pp")
model2 = transformers.pipeline("text2text-generation", model="google/flan-t5-xxl")
model3 = transformers.pipeline("text2text-generation", model="google/flan-t5-xl")
model4 = transformers.pipeline("text2text-generation", model="tuner007/pegasus_paraphrase")
model5 = transformers.pipeline("text2text-generation", model="tuner007/pegasus_paraphrase")
# Define the Streamlit app
def main():
st.title("Topic Modeling with Hugging Face")
text = st.text_area("Enter some text to generate topics", height=200)
if st.button("Generate Topics"):
# Generate topics
topics1 = model1(text, max_length=50, do_sample=True, num_beams=5, temperature=0.7)
topics2 = model2(text, max_length=50, do_sample=True, num_beams=5, temperature=0.7)
topics3 = model3(text, max_length=50, do_sample=True, num_beams=5, temperature=0.7)
topics4 = model4(text, max_length=50, do_sample=True, num_beams=5, temperature=0.7)
topics5 = model5(text, max_length=50, do_sample=True, num_beams=5, temperature=0.7)
# Print topics
st.write("Top 5 topics:")
for i in range(5):
st.write(f"{i+1}. {topics1[i]['generated_text']}")
st.write(f"{i+1}. {topics2[i]['generated_text']}")
st.write(f"{i+1}. {topics3[i]['generated_text']}")
st.write(f"{i+1}. {topics4[i]['generated_text']}")
st.write(f"{i+1}. {topics5[i]['generated_text']}")
if __name__ == "__main__":
main()