Spaces:
Sleeping
Sleeping
Duplicate from AI-Beast/Daily-Horoscope-Generator
Browse filesCo-authored-by: AI Beast <[email protected]>
- .gitattributes +34 -0
- README.md +14 -0
- get_word.pkl +3 -0
- horoscopeModel.h5 +3 -0
- horoscope_app.py +178 -0
- horoscope_model.pkl +3 -0
- horoscope_model1.pkl +3 -0
- horoscope_tokenizer.pkl +3 -0
- horoscopes.csv +0 -0
- requirements.txt +12 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Horoscope Generator
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.15.2
|
8 |
+
app_file: horoscope_app.py
|
9 |
+
pinned: false
|
10 |
+
license: openrail
|
11 |
+
duplicated_from: AI-Beast/Daily-Horoscope-Generator
|
12 |
+
---
|
13 |
+
|
14 |
+
Visit for more powerful tools www.aibeast.net
|
get_word.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc9e6af2e802eb4b7a9442fe2dd6f74a2b9fd21a39914da273817179ad5159e8
|
3 |
+
size 102086
|
horoscopeModel.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8dfac5b862122070245c2a432e230145e67abd46f4fcf983b15d6d136e4faa29
|
3 |
+
size 6377648
|
horoscope_app.py
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import string
|
4 |
+
import time
|
5 |
+
#import re
|
6 |
+
#import torch
|
7 |
+
#import tensorflow as tf
|
8 |
+
#import matplotlib.pyplot as plt
|
9 |
+
import pickle as pkl
|
10 |
+
import streamlit as st
|
11 |
+
from wordcloud import WordCloud, STOPWORDS
|
12 |
+
from deepmultilingualpunctuation import PunctuationModel
|
13 |
+
from tensorflow.keras.preprocessing.text import Tokenizer
|
14 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
15 |
+
from tensorflow.keras.models import load_model
|
16 |
+
from tensorflow.python.keras.saving.hdf5_format import save_attributes_to_hdf5_group
|
17 |
+
|
18 |
+
|
19 |
+
@st.cache(allow_output_mutation=True)
|
20 |
+
def load_horoscope_model():
|
21 |
+
model=load_model('horoscopeModel.h5')
|
22 |
+
return model
|
23 |
+
|
24 |
+
model = load_horoscope_model()
|
25 |
+
|
26 |
+
@st.cache(allow_output_mutation = True)
|
27 |
+
def load_punc_model():
|
28 |
+
punctuation_model = PunctuationModel()
|
29 |
+
return punctuation_model
|
30 |
+
|
31 |
+
punctuation_model = load_punc_model()
|
32 |
+
|
33 |
+
|
34 |
+
@st.cache
|
35 |
+
def load_get_word():
|
36 |
+
# open the get_word file
|
37 |
+
fileo = open('get_word.pkl' , "rb")
|
38 |
+
# loading data
|
39 |
+
get_word = pkl.load(fileo)
|
40 |
+
return get_word
|
41 |
+
|
42 |
+
get_word = load_get_word()
|
43 |
+
|
44 |
+
@st.cache
|
45 |
+
def load_tokenizer():
|
46 |
+
# open the horoscope_tokenizer file
|
47 |
+
fileo = open('horoscope_tokenizer.pkl' , "rb")
|
48 |
+
# loading data
|
49 |
+
tokenizer = pkl.load(fileo)
|
50 |
+
return tokenizer
|
51 |
+
|
52 |
+
tokenizer = load_tokenizer()
|
53 |
+
|
54 |
+
|
55 |
+
# with st.spinner("Loading the cosmos..."):
|
56 |
+
# # #load models
|
57 |
+
# # punctuation_model = PunctuationModel()
|
58 |
+
|
59 |
+
# # # open the model file
|
60 |
+
# # model=load_model('horoscopeModel.h5')
|
61 |
+
# # # model.summary()
|
62 |
+
|
63 |
+
# # open the get_word file
|
64 |
+
# fileo = open('get_word.pkl' , "rb")
|
65 |
+
# # loading data
|
66 |
+
# get_word = pkl.load(fileo)
|
67 |
+
|
68 |
+
# # open the horoscope_tokenizer file
|
69 |
+
# fileo = open('horoscope_tokenizer.pkl' , "rb")
|
70 |
+
# # loading data
|
71 |
+
# tokenizer = pkl.load(fileo)
|
72 |
+
|
73 |
+
|
74 |
+
# #load data
|
75 |
+
# url = 'https://raw.githubusercontent.com/nicsusuki/horoscope-streamlit-app/main/horoscopes.csv'
|
76 |
+
# data = pd.read_csv(url,
|
77 |
+
# error_bad_lines=False,
|
78 |
+
# sep = "|", header = None,
|
79 |
+
# names = ["text", "date", "sign"], index_col = 0)
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
st.title("Horoscope Generator")
|
91 |
+
st.markdown('This uses NLP on 3 years worth of NYT horoscopes to generate your own horoscope based on user inputted seed text. The algorithm employs an element of randomness so that no two horoscopes are the same.')
|
92 |
+
|
93 |
+
st.markdown('Visit for more powerful tools')
|
94 |
+
st.markdown('https://aibeast.net')
|
95 |
+
st.markdown('Follow')
|
96 |
+
st.markdown('https://twitter.com/AIBeastWeb')
|
97 |
+
query = st.selectbox(
|
98 |
+
'What is your sign?',
|
99 |
+
('Aries','Taurus','Gemini','Cancer','Leo','Virgo','Libra', 'Scorpio',
|
100 |
+
'Sagitarius', 'Capricorn','Aquarius', 'Pisces', 'Generate my own'))
|
101 |
+
|
102 |
+
if query == 'Generate my own':
|
103 |
+
query = st.text_input("Type horoscope seed text here")
|
104 |
+
|
105 |
+
search_button = st.button('Search the cosmos!')
|
106 |
+
|
107 |
+
# words = ""
|
108 |
+
# stopwords = set(STOPWORDS)
|
109 |
+
# for review in data.text.values:
|
110 |
+
# text = str(review)
|
111 |
+
# text = text.split()
|
112 |
+
# words += " ".join([(i.lower() + " ") for i in text])
|
113 |
+
|
114 |
+
# #cleaning function - lowercase, remove punc
|
115 |
+
# def clean_text(text):
|
116 |
+
# words = str(text).split()
|
117 |
+
# words = [i.lower() + " " for i in words]
|
118 |
+
# words = " ".join(words)
|
119 |
+
# words = words.translate(words.maketrans('', '', string.punctuation))
|
120 |
+
# return words
|
121 |
+
|
122 |
+
# data['text'] = data['text'].apply(clean_text)
|
123 |
+
|
124 |
+
# #tokenize the data
|
125 |
+
vocab_size = 15000
|
126 |
+
# max_length = 50
|
127 |
+
# oov_tok = "<OOV>"
|
128 |
+
|
129 |
+
# tokenizer = Tokenizer(num_words = vocab_size, oov_token = oov_tok)
|
130 |
+
# tokenizer.fit_on_texts(data.text.values)
|
131 |
+
# word_index = tokenizer.word_index
|
132 |
+
|
133 |
+
# get_word = {v: k for k, v in word_index.items()}
|
134 |
+
|
135 |
+
# #create n-grams
|
136 |
+
# sequences = tokenizer.texts_to_sequences(data.text.values[::100])
|
137 |
+
|
138 |
+
# n_gram_sequences = []
|
139 |
+
# for sequence in sequences:
|
140 |
+
# for i,j in enumerate(sequence):
|
141 |
+
# if i < (len(sequence) - 10):
|
142 |
+
# s = sequence[i:i + 10]
|
143 |
+
# for k, l in enumerate(s):
|
144 |
+
# n_gram_sequences.append(s[:k + 1])
|
145 |
+
|
146 |
+
# np.array(n_gram_sequences).shape
|
147 |
+
|
148 |
+
# n_gram_sequences = np.array(n_gram_sequences)
|
149 |
+
max_len = 10 #max([len(i) for i in n_gram_sequences]) ##max len = 10
|
150 |
+
|
151 |
+
#predict horoscopes
|
152 |
+
avg_length = 44 #int(len(words.split())/len(data)) ## average length of horoscope 44
|
153 |
+
|
154 |
+
#takes seed text and generates horoscopes using closest matching words
|
155 |
+
#uses random choice element to change horoscopes returned
|
156 |
+
#@st.cache
|
157 |
+
def write_horoscope(seed_text):
|
158 |
+
for _ in range(avg_length):
|
159 |
+
token_list = tokenizer.texts_to_sequences([seed_text])[0]
|
160 |
+
token_list = pad_sequences([token_list], maxlen=max_len-1, padding='pre')
|
161 |
+
pred_probs = model.predict(token_list)
|
162 |
+
predicted = np.random.choice(np.linspace(0, vocab_size - 1, vocab_size), p = pred_probs[0])
|
163 |
+
if predicted == 1: ## if it's OOV, pick the next most likely one.
|
164 |
+
pred_probs[0][1] = 0
|
165 |
+
predicted = np.argmax(pred_probs)
|
166 |
+
output_word = get_word[predicted]
|
167 |
+
seed_text += " " + output_word
|
168 |
+
return seed_text
|
169 |
+
|
170 |
+
|
171 |
+
if search_button:
|
172 |
+
st.markdown("**Searching the cosmos for your horoscope:** " + query)
|
173 |
+
with st.spinner("Consulting the oracle..."):
|
174 |
+
time.sleep(2)
|
175 |
+
horoscope_text = write_horoscope(query)
|
176 |
+
horoscope = punctuation_model.restore_punctuation(horoscope_text)
|
177 |
+
st.success(horoscope)
|
178 |
+
|
horoscope_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8bb601ed33774b64cba1fa7d6fa2b12b96243b77721f3bf82a2a107cb05e7784
|
3 |
+
size 21330150
|
horoscope_model1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e8517a34b6671f6b4a9042a96c90373d647e6690787f6b05b9b826e0a0d0e310
|
3 |
+
size 21330150
|
horoscope_tokenizer.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:35637c66b492ac59063b18676b0423e51e5350ea777f4533d267bdfe0d5703b3
|
3 |
+
size 308539
|
horoscopes.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
plotly
|
3 |
+
streamlit
|
4 |
+
torch
|
5 |
+
tensorflow==2.9.2
|
6 |
+
keras==2.9.0
|
7 |
+
Keras-Preprocessing==1.1.2
|
8 |
+
deepmultilingualpunctuation
|
9 |
+
sentencepiece
|
10 |
+
transformers==4.25.1
|
11 |
+
wordcloud
|
12 |
+
matplotlib
|