File size: 1,480 Bytes
dc131b2 4ea0b05 dc131b2 d7e24f9 dc131b2 |
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 |
import streamlit as st
from collections import Counter
import plotly.express as px
import numpy as np
def get_word_score(word):
# This function returns a score based on the length of the word
# Modify this function as per your requirements
score = len(word)**2
return score
def get_word_frequency(text):
# This function returns the word frequency of the given text
words = text.split()
word_frequency = Counter(words)
return word_frequency
# Load the markdown file
with open('Setup.md', 'r') as file:
text = file.read()
# Display the parsed markdown
st.markdown(text, unsafe_allow_html=True)
# Get the word frequency of the markdown text
word_frequency = get_word_frequency(text)
# Get the top words and their frequency
top_words = word_frequency.most_common(10)
top_words_dict = dict(top_words)
# Create a Plotly bar chart to display the top words and their frequency
fig = px.bar(x=list(top_words_dict.keys()), y=list(top_words_dict.values()), labels={'x':'Word', 'y':'Frequency'})
st.plotly_chart(fig)
# Calculate the scores for each word based on their length
word_scores = {word:get_word_score(word) for word in word_frequency}
top_word_scores = dict(sorted(word_scores.items(), key=lambda item: item[1], reverse=True)[:10])
# Create a Plotly bar chart to display the top words and their scores
fig = px.bar(x=list(top_word_scores.keys()), y=list(top_word_scores.values()), labels={'x':'Word', 'y':'Score'})
st.plotly_chart(fig)
|