Topic-modeling / app.py
awacke1's picture
Create app.py
f0a7780
raw
history blame
699 Bytes
import streamlit as st
import transformers
import numpy as np
# Load the pre-trained model
model = transformers.pipeline("text2text-generation", model="mrm8488/t5-base-finetuned-topic-modeling")
# 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
topics = model(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}. {topics[i]['generated_text']}")
if __name__ == "__main__":
main()