awacke1 commited on
Commit
43216af
1 Parent(s): 9d44137

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -9
app.py CHANGED
@@ -1,11 +1,63 @@
 
 
 
 
 
 
 
1
 
2
- from diagrams import Diagram
3
- from diagrams.k8s.clusterconfig import HPA
4
- from diagrams.k8s.compute import Deployment, Pod, ReplicaSet
5
- from diagrams.k8s.network import Ingress, Service
6
 
7
- with Diagram("Exposed Pod with 3 Replicas", show=False):
8
- net = Ingress("domain.com") >> Service("svc")
9
- net >> [Pod("pod1"),
10
- Pod("pod2"),
11
- Pod("pod3")] << ReplicaSet("rs") << Deployment("dp") << HPA("hpa")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from transformers import pipeline
4
+ import plotly.express as px
5
+ import pandas as pd
6
+ from collections import Counter
7
+ import re
8
 
9
+ def get_markdown_from_github(url):
10
+ response = requests.get(url)
11
+ markdown = response.text
12
+ return markdown
13
 
14
+ def preprocess_text(text):
15
+ text = text.lower()
16
+ text = re.sub('[^A-Za-z0-9]+', ' ', text)
17
+ return text
18
+
19
+ def get_most_frequent_words(text, n):
20
+ words = re.findall(r'\b\w{5,}\b', text)
21
+ word_count = Counter(words)
22
+ most_common_words = word_count.most_common(n)
23
+ return most_common_words
24
+
25
+ def get_sentences_with_common_words(text, common_words):
26
+ sentences = re.split('[.?!]', text)
27
+ selected_sentences = []
28
+ for sentence in sentences:
29
+ for word in common_words:
30
+ if word in sentence:
31
+ selected_sentences.append(sentence.strip())
32
+ break
33
+ return selected_sentences
34
+
35
+ def render_heatmap(words, sentences):
36
+ df = pd.DataFrame(words, columns=['word', 'frequency'])
37
+ fig = px.treemap(df, path=['word'], values='frequency', color='frequency', hover_data=['frequency'], color_continuous_scale='reds')
38
+ st.plotly_chart(fig, use_container_width=True)
39
+
40
+ def main():
41
+ st.title('Markdown Analyzer')
42
+
43
+ # Get markdown from GitHub
44
+ default_markdown_url = 'https://github.com/AaronCWacker/Yggdrasil/blob/main/README.md'
45
+ markdown_url = st.sidebar.text_input("Enter a URL to analyze (default is provided):", default_markdown_url)
46
+ markdown = get_markdown_from_github(markdown_url)
47
+
48
+ # Preprocess text
49
+ text = preprocess_text(markdown)
50
+
51
+ # Get most frequent words
52
+ n_most_frequent_words = st.sidebar.slider('Number of most frequent words to display', 1, 20, 10)
53
+ most_frequent_words = get_most_frequent_words(text, n_most_frequent_words)
54
+
55
+ # Get sentences containing common words
56
+ common_words = [word for word, _ in most_frequent_words]
57
+ sentences = get_sentences_with_common_words(text, common_words)
58
+
59
+ # Render heatmap
60
+ render_heatmap(most_frequent_words, sentences)
61
+
62
+ if __name__ == '__main__':
63
+ main()