File size: 1,750 Bytes
7b06f86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pandas as pd
import joblib
from gensim import corpora, models
from PIL import Image

# Load the saved models and data
dictionary = joblib.load('doc2bow.sav')
lda_model = joblib.load('ldamodel.sav')

# Function to preprocess input text and get topic distribution
def get_topics(text):
    bow_vector = dictionary(text.split())
    topics = lda_model[bow_vector]
    return topics

# Function to get top keywords for a topic
def get_top_keywords(topic, num_keywords=10):
    topic = lda_model.show_topic(topic, topn=num_keywords)
    keywords = [f"{word} ({weight:.3f})" for word, weight in topic]
    return keywords

# Streamlit app
def main():
    st.title("Aplikasi Diskusi Topic Produk Menggunakan Latent Dirichlet Allocation pada Komentar Youtube📰")

     # Sidebar with title and description
    st.sidebar.title("Aplikasi Diskusi Topic Produk")
    st.sidebar.write("Menemukan topik di Komentar Youtube.")
    
    # Input text area for user to enter their text
    user_input = st.text_area("Masukkan Komentar Youtube:")
    
    # Submit button
    if st.button("Kirim"):
        if user_input:
            # Process the user's input and get topic distribution
            topics = get_topics(user_input)
            
            # Display the top topics
            st.subheader("🔥Top Topik🔥")
            for topic in topics:
                st.write(f"**📍Topik {topic[0] + 1}** (Skor: {topic[1]:.4f})")
                top_keywords = get_top_keywords(topic[0])
                st.markdown(", ".join(top_keywords))
                st.write("---")

    # Add a footer
    st.sidebar.markdown("---")
    st.sidebar.write("© 2023 Aplikasi Diskusi Topic Produk")

if __name__ == "__main__":
    main()