Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import markdown
|
| 3 |
+
from collections import Counter
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
def get_word_score(word):
|
| 8 |
+
# This function returns a score based on the length of the word
|
| 9 |
+
# Modify this function as per your requirements
|
| 10 |
+
score = len(word)**2
|
| 11 |
+
return score
|
| 12 |
+
|
| 13 |
+
def get_word_frequency(text):
|
| 14 |
+
# This function returns the word frequency of the given text
|
| 15 |
+
words = text.split()
|
| 16 |
+
word_frequency = Counter(words)
|
| 17 |
+
return word_frequency
|
| 18 |
+
|
| 19 |
+
# Load the markdown file
|
| 20 |
+
with open('example.md', 'r') as file:
|
| 21 |
+
text = file.read()
|
| 22 |
+
|
| 23 |
+
# Parse the markdown using the markdown library
|
| 24 |
+
html = markdown.markdown(text)
|
| 25 |
+
|
| 26 |
+
# Display the parsed markdown
|
| 27 |
+
st.markdown(html, unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
+
# Get the word frequency of the markdown text
|
| 30 |
+
word_frequency = get_word_frequency(text)
|
| 31 |
+
|
| 32 |
+
# Get the top words and their frequency
|
| 33 |
+
top_words = word_frequency.most_common(10)
|
| 34 |
+
top_words_dict = dict(top_words)
|
| 35 |
+
|
| 36 |
+
# Create a Plotly bar chart to display the top words and their frequency
|
| 37 |
+
fig = px.bar(x=list(top_words_dict.keys()), y=list(top_words_dict.values()), labels={'x':'Word', 'y':'Frequency'})
|
| 38 |
+
st.plotly_chart(fig)
|
| 39 |
+
|
| 40 |
+
# Calculate the scores for each word based on their length
|
| 41 |
+
word_scores = {word:get_word_score(word) for word in word_frequency}
|
| 42 |
+
top_word_scores = dict(sorted(word_scores.items(), key=lambda item: item[1], reverse=True)[:10])
|
| 43 |
+
|
| 44 |
+
# Create a Plotly bar chart to display the top words and their scores
|
| 45 |
+
fig = px.bar(x=list(top_word_scores.keys()), y=list(top_word_scores.values()), labels={'x':'Word', 'y':'Score'})
|
| 46 |
+
st.plotly_chart(fig)
|