Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,3 @@
|
|
1 |
-
#TorchNeuralNetworkNLTKRequests
|
2 |
-
#Create a torch demonstration and use data created with this program below for input and output. Design a torch demo that uses simple convolutions to explain correlation between one word and another and add to IO patterns of this program and use requests and nlp including nltk to remix a demonstration app that uses the text files as input.
|
3 |
-
#Have this allow users to build their library of prompts and add it to their user file defined by email address named text file.
|
4 |
-
#Add links to sites with reference documentation. Use this as teaching lesson in python streamlit UI and code yet remove all comments and just have variable names be super descriptive
|
5 |
import streamlit as st
|
6 |
import torch
|
7 |
import torch.nn as nn
|
@@ -24,6 +20,19 @@ def text_convolution(input_text, kernel_size=3):
|
|
24 |
output = conv_layer(tensor_input)
|
25 |
return output, words
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Streamlit UI
|
28 |
def main():
|
29 |
st.title("Text Convolution Demonstration")
|
@@ -39,7 +48,9 @@ def main():
|
|
39 |
|
40 |
# Visualization
|
41 |
word_counts = pd.Series(words).value_counts()
|
42 |
-
|
|
|
|
|
43 |
|
44 |
# Saving user prompts
|
45 |
user_file_name = f"{user_email}_prompts.txt"
|
@@ -56,17 +67,3 @@ def main():
|
|
56 |
if __name__ == "__main__":
|
57 |
main()
|
58 |
|
59 |
-
|
60 |
-
#Create requirements.txt import streamlit as st
|
61 |
-
#import torch
|
62 |
-
#import torch.nn as nn
|
63 |
-
#import nltk
|
64 |
-
#from nltk.corpus import stopwords
|
65 |
-
#import requests
|
66 |
-
#import os
|
67 |
-
|
68 |
-
#streamlit
|
69 |
-
#torch
|
70 |
-
#nltk
|
71 |
-
#requests
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
import torch.nn as nn
|
|
|
20 |
output = conv_layer(tensor_input)
|
21 |
return output, words
|
22 |
|
23 |
+
|
24 |
+
# Function to color the bars based on whether they appear together or not
|
25 |
+
def color_bars(words):
|
26 |
+
color_map = {}
|
27 |
+
color_index = 0
|
28 |
+
for word in words:
|
29 |
+
if word not in color_map:
|
30 |
+
color_map[word] = color_index
|
31 |
+
color_index += 1
|
32 |
+
colors = [f"#{random.randint(0, 0xFFFFFF):06x}" for _ in range(len(color_map))]
|
33 |
+
return [colors[color_map[word]] for word in words]
|
34 |
+
|
35 |
+
|
36 |
# Streamlit UI
|
37 |
def main():
|
38 |
st.title("Text Convolution Demonstration")
|
|
|
48 |
|
49 |
# Visualization
|
50 |
word_counts = pd.Series(words).value_counts()
|
51 |
+
word_counts = word_counts.sort_values(ascending=False)
|
52 |
+
colors = color_bars(word_counts.index)
|
53 |
+
st.bar_chart(word_counts.head(20), color=colors)
|
54 |
|
55 |
# Saving user prompts
|
56 |
user_file_name = f"{user_email}_prompts.txt"
|
|
|
67 |
if __name__ == "__main__":
|
68 |
main()
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|