Spaces:
Sleeping
Sleeping
| 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) | |