File size: 3,800 Bytes
51ee1a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from transformers import GPT2LMHeadModel, GPT2Tokenizer
import streamlit as st
import torch
# import yake
# from rake_nltk import Rake
# rake_nltk_var = Rake()


st.set_page_config(
    page_title="Khayal-Writing Tool App"
)
st.sidebar.success("Select an App")
#
# page_bg_img = """
# <style>
# [data-testid="stAppViewContainer"] {
# background-image url("https://images.unsplash.com/photo-1490633874781-1c63cc424610?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80");
# background-size: cover;
# }
# <style>
# """
# st.markdown(page_bg_img, unsafe_allow_html= True)
def add_bg_from_url():
    st.markdown(
         f"""
         <style>
         .stApp {{
             background-image: url("https://images.unsplash.com/photo-1488415032361-b7e238421f1b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2069&q=80");
             background-attachment: fixed;
             background-size: cover
         }}
         [data-testid="stHeader"] {{
         background-color: rgba(0,0,0,0);
         }}
         [data-testid="stSidebar"] {{
         background-image: url("https://images.unsplash.com/photo-1487528742387-d53d4f12488d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1922&q=80");
         background-size: cover;
         }}
         </style>
         
         """,
         unsafe_allow_html=True
     )

add_bg_from_url()

#primaryColor="#F63366"
#backgroundColor="#FFFFFF"
#secondaryBackgroundColor="#F0F2F6"
textColor="#262730"
font="Serif"




#
# base="dark"
# primaryColor="purple"
#st.title("Khayal- Writing Tool ")
st.markdown("<h1 style='text-align: center; color: white;'>Khayal- Writing Tool</h1>", unsafe_allow_html=True)
st.write("This writing tool currently has two applications within it, poem generation and text summarizer."
         " To summarize text you can use 'Summarizer from the sidebar. ")
st.header("Poem Generation")
st.markdown("This is a poem generator app. you can use it to create poems by providing text to it.")

@st.cache(allow_output_mutation=True)
def get_model():
    tokenizer = GPT2Tokenizer.from_pretrained("Silvers-145/khayal-generate")
    model = GPT2LMHeadModel.from_pretrained("Silvers-145/khayal-generate")
    return tokenizer, model

tokenizer,model = get_model()

# # load the model
# #model = GPT2LMHeadModel.from_pretrained("Silvers-145/khayal-generate")
# #tokenizer = GPT2Tokenizer.from_pretrained("Silvers-145/khayal-generate")

#model.eval()

#prompt = input("Enter the start of poem here:")
#button = st.button("Create")

prompt = st.text_input("Enter Text:",placeholder="Enter The text here")
click = st.button("Create")
if click and prompt:
    generated = torch.tensor(tokenizer.encode(prompt)).unsqueeze(0)

    sample_outputs = model.generate(
        generated,
        do_sample=True,
        top_k=50,
        max_length=300,
        top_p=0.95,
        num_return_sequences=3
    )

    for i, sample_output in enumerate(sample_outputs):
        poemm = tokenizer.decode(sample_output, skip_special_tokens=True)
    # print("{}: {}\n\n".format(i,


    st.text_area("Generated Poem:", poemm,height=250)
 #   st.snow()
    st.success("Poem Generated")



# kw_extractor = yake.KeywordExtractor()
# text = poemm
# language = "en"
# max_ngram_size = 3
# deduplication_threshold = 0.9
# numOfKeywords = 5
# custom_kw_extractor = yake.KeywordExtractor(lan=language, n=max_ngram_size, dedupLim=deduplication_threshold, top=numOfKeywords, features=None)
# keywords = custom_kw_extractor.extract_keywords(text)
# for kw in keywords:
#     print(kw)

# from rake_nltk import Rake
# rake_nltk_var = Rake()
# rake_nltk_var.extract_keywords_from_text(poemm)
# kw = rake_nltk_var.get_ranked_phrases()
# st.t