salsabilapl commited on
Commit
7b06f86
1 Parent(s): 200a638

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from gensim import corpora, models
5
+ from PIL import Image
6
+
7
+ # Load the saved models and data
8
+ dictionary = joblib.load('doc2bow.sav')
9
+ lda_model = joblib.load('ldamodel.sav')
10
+
11
+ # Function to preprocess input text and get topic distribution
12
+ def get_topics(text):
13
+ bow_vector = dictionary(text.split())
14
+ topics = lda_model[bow_vector]
15
+ return topics
16
+
17
+ # Function to get top keywords for a topic
18
+ def get_top_keywords(topic, num_keywords=10):
19
+ topic = lda_model.show_topic(topic, topn=num_keywords)
20
+ keywords = [f"{word} ({weight:.3f})" for word, weight in topic]
21
+ return keywords
22
+
23
+ # Streamlit app
24
+ def main():
25
+ st.title("Aplikasi Diskusi Topic Produk Menggunakan Latent Dirichlet Allocation pada Komentar Youtube📰")
26
+
27
+ # Sidebar with title and description
28
+ st.sidebar.title("Aplikasi Diskusi Topic Produk")
29
+ st.sidebar.write("Menemukan topik di Komentar Youtube.")
30
+
31
+ # Input text area for user to enter their text
32
+ user_input = st.text_area("Masukkan Komentar Youtube:")
33
+
34
+ # Submit button
35
+ if st.button("Kirim"):
36
+ if user_input:
37
+ # Process the user's input and get topic distribution
38
+ topics = get_topics(user_input)
39
+
40
+ # Display the top topics
41
+ st.subheader("🔥Top Topik🔥")
42
+ for topic in topics:
43
+ st.write(f"**📍Topik {topic[0] + 1}** (Skor: {topic[1]:.4f})")
44
+ top_keywords = get_top_keywords(topic[0])
45
+ st.markdown(", ".join(top_keywords))
46
+ st.write("---")
47
+
48
+ # Add a footer
49
+ st.sidebar.markdown("---")
50
+ st.sidebar.write("© 2023 Aplikasi Diskusi Topic Produk")
51
+
52
+ if __name__ == "__main__":
53
+ main()