Abu1998 commited on
Commit
46ce3e0
·
verified ·
1 Parent(s): 963a193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -70
app.py CHANGED
@@ -4,77 +4,57 @@ import seaborn as sns
4
  import matplotlib.pyplot as plt
5
  from dataset_import import load_data
6
  from data_cleaning import clean_data
7
- from YTCommentScraper import get_transcript, summarize_with_langchain_and_openai
8
 
9
  st.title("AnalyzeYT Dataset Analysis")
10
 
11
- # Option to extract YouTube comments
12
- extract_comments = st.radio("Do you want to extract comments from a YouTube video?", ("No", "Yes"))
13
-
14
- if extract_comments == "Yes":
15
- openai_api_key = st.text_input("Enter your OpenAI API Key:", type='password')
16
- video_id = st.text_input("Enter the YouTube Video ID:")
17
-
18
- if st.button('Extract and Summarize Comments'):
19
- if openai_api_key and video_id:
20
- try:
21
- transcript, language_code = get_transcript(video_id)
22
- summary = summarize_with_langchain_and_openai(transcript, language_code, openai_api_key)
23
- st.write("Summary of YouTube Comments:")
24
- st.markdown(summary)
25
- except Exception as e:
26
- st.write(str(e))
27
- else:
28
- st.write("Please enter both your OpenAI API Key and YouTube Video ID.")
29
- else:
30
- # Proceed with normal data analysis
31
- data = load_data()
32
-
33
- if data is not None:
34
- st.write("Loaded Data Preview:")
35
- st.write(data.head())
36
-
37
- # Clean data
38
- data = clean_data(data)
39
-
40
- st.write("Cleaned Data Preview:")
41
- st.write(data.head())
42
-
43
- # Show data description of cleaned data
44
- st.write("Cleaned Data Description:")
45
- st.write(data.describe())
46
-
47
- # Add correlation matrix for cleaned data
48
- st.write("Correlation Matrix of Cleaned Data:")
49
- corr = data.corr()
50
- st.write(corr)
51
- sns.heatmap(corr, annot=True, cmap='coolwarm')
 
 
 
 
 
 
 
 
 
52
  st.pyplot()
53
-
54
- # Data visualization options for cleaned data
55
- st.write("Data Visualization on Cleaned Data:")
56
- chart_type = st.selectbox("Select Chart Type", ['Line Chart', 'Bar Chart', 'Histogram'])
57
-
58
- if chart_type == 'Line Chart':
59
- x_axis = st.selectbox("Select X-axis Column", data.columns)
60
- y_axis = st.selectbox("Select Y-axis Column", data.columns)
61
- title = st.text_input("Enter Chart Title", "Line Chart")
62
- st.line_chart(data[[x_axis, y_axis]])
63
- st.write(f"Line Chart: {title}")
64
-
65
- elif chart_type == 'Bar Chart':
66
- x_axis = st.selectbox("Select X-axis Column", data.columns)
67
- y_axis = st.selectbox("Select Y-axis Column", data.columns)
68
- title = st.text_input("Enter Chart Title", "Bar Chart")
69
- st.bar_chart(data[[x_axis, y_axis]])
70
- st.write(f"Bar Chart: {title}")
71
-
72
- elif chart_type == 'Histogram':
73
- selected_column = st.selectbox("Select Column for Histogram", data.columns)
74
- bins = st.slider("Number of Bins", min_value=10, max_value=100, value=30)
75
- title = st.text_input("Enter Chart Title", "Histogram")
76
- plt.hist(data[selected_column], bins=bins)
77
- plt.title(title)
78
- plt.xlabel(selected_column)
79
- plt.ylabel('Frequency')
80
- st.pyplot()
 
4
  import matplotlib.pyplot as plt
5
  from dataset_import import load_data
6
  from data_cleaning import clean_data
 
7
 
8
  st.title("AnalyzeYT Dataset Analysis")
9
 
10
+ # Load dataset
11
+ data = load_data()
12
+
13
+ if data is not None:
14
+ st.write("Loaded Data Preview:")
15
+ st.write(data.head())
16
+
17
+ # Clean data
18
+ data = clean_data(data)
19
+
20
+ st.write("Cleaned Data Preview:")
21
+ st.write(data.head())
22
+
23
+ # Show data description of cleaned data
24
+ st.write("Cleaned Data Description:")
25
+ st.write(data.describe())
26
+
27
+ # Add correlation matrix for cleaned data
28
+ st.write("Correlation Matrix of Cleaned Data:")
29
+ corr = data.corr()
30
+ st.write(corr)
31
+ sns.heatmap(corr, annot=True, cmap='coolwarm')
32
+ st.pyplot()
33
+
34
+ # Data visualization options for cleaned data
35
+ st.write("Data Visualization on Cleaned Data:")
36
+ chart_type = st.selectbox("Select Chart Type", ['Line Chart', 'Bar Chart', 'Histogram'])
37
+
38
+ if chart_type == 'Line Chart':
39
+ x_axis = st.selectbox("Select X-axis Column", data.columns)
40
+ y_axis = st.selectbox("Select Y-axis Column", data.columns)
41
+ title = st.text_input("Enter Chart Title", "Line Chart")
42
+ st.line_chart(data[[x_axis, y_axis]])
43
+ st.write(f"Line Chart: {title}")
44
+
45
+ elif chart_type == 'Bar Chart':
46
+ x_axis = st.selectbox("Select X-axis Column", data.columns)
47
+ y_axis = st.selectbox("Select Y-axis Column", data.columns)
48
+ title = st.text_input("Enter Chart Title", "Bar Chart")
49
+ st.bar_chart(data[[x_axis, y_axis]])
50
+ st.write(f"Bar Chart: {title}")
51
+
52
+ elif chart_type == 'Histogram':
53
+ selected_column = st.selectbox("Select Column for Histogram", data.columns)
54
+ bins = st.slider("Number of Bins", min_value=10, max_value=100, value=30)
55
+ title = st.text_input("Enter Chart Title", "Histogram")
56
+ plt.hist(data[selected_column], bins=bins)
57
+ plt.title(title)
58
+ plt.xlabel(selected_column)
59
+ plt.ylabel('Frequency')
60
  st.pyplot()