Spaces:
Runtime error
Runtime error
Commit
·
7e5e944
1
Parent(s):
39bac6a
Upload Shakespeare.py
Browse files- Shakespeare.py +114 -0
Shakespeare.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import time
|
3 |
+
from datetime import datetime
|
4 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
5 |
+
import numpy as np
|
6 |
+
import torch
|
7 |
+
# from streamlit_chat import message as st_message
|
8 |
+
|
9 |
+
|
10 |
+
html_temp= """
|
11 |
+
<div style="background-color:tomato;padding:10px">
|
12 |
+
<h2 style="color:white;text-align:centre;"> Shakespeare-AI.</h2>
|
13 |
+
</div>
|
14 |
+
"""
|
15 |
+
st.markdown(html_temp,unsafe_allow_html=True)
|
16 |
+
|
17 |
+
st.markdown(
|
18 |
+
|
19 |
+
"""
|
20 |
+
This is an AI tool. This AI chatbot is able to talk to you like Shakespeare.
|
21 |
+
"""
|
22 |
+
)
|
23 |
+
output_path = "SurendraKumarDhaka/output"
|
24 |
+
# Load the trained model and tokenizer
|
25 |
+
tokenizer = GPT2Tokenizer.from_pretrained(output_path)
|
26 |
+
model = GPT2LMHeadModel.from_pretrained(output_path)
|
27 |
+
|
28 |
+
input_text = st.text_area("Type your text..")
|
29 |
+
st.button("Submit")
|
30 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
31 |
+
# Generate text using the model
|
32 |
+
output = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)
|
33 |
+
# Decode the generated text
|
34 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
35 |
+
st.write(generated_text)
|
36 |
+
st.text("Thanks for using")
|
37 |
+
|
38 |
+
if st.button("About"):
|
39 |
+
st.text("Created by Surendra Kumar")
|
40 |
+
## footer
|
41 |
+
from htbuilder import HtmlElement, div, ul, li, br, hr, a, p, img, styles, classes, fonts
|
42 |
+
from htbuilder.units import percent, px
|
43 |
+
from htbuilder.funcs import rgba, rgb
|
44 |
+
|
45 |
+
|
46 |
+
def image(src_as_string, **style):
|
47 |
+
return img(src=src_as_string, style=styles(**style))
|
48 |
+
|
49 |
+
|
50 |
+
def link(link, text, **style):
|
51 |
+
return a(_href=link, _target="_blank", style=styles(**style))(text)
|
52 |
+
|
53 |
+
|
54 |
+
def layout(*args):
|
55 |
+
style = """
|
56 |
+
<style>
|
57 |
+
# MainMenu {visibility: hidden;}
|
58 |
+
footer {visibility: hidden;}
|
59 |
+
.stApp { bottom: 105px; }
|
60 |
+
</style>
|
61 |
+
"""
|
62 |
+
|
63 |
+
style_div = styles(
|
64 |
+
position="fixed",
|
65 |
+
left=0,
|
66 |
+
bottom=0,
|
67 |
+
margin=px(0, 0, 0, 0),
|
68 |
+
width=percent(100),
|
69 |
+
color="black",
|
70 |
+
text_align="center",
|
71 |
+
height="auto",
|
72 |
+
opacity=1
|
73 |
+
)
|
74 |
+
|
75 |
+
style_hr = styles(
|
76 |
+
display="block",
|
77 |
+
margin=px(8, 8, "auto", "auto"),
|
78 |
+
border_style="solid",
|
79 |
+
border_width=px(0.5)
|
80 |
+
)
|
81 |
+
|
82 |
+
body = p()
|
83 |
+
foot = div(
|
84 |
+
style=style_div
|
85 |
+
)(
|
86 |
+
hr(
|
87 |
+
style=style_hr
|
88 |
+
),
|
89 |
+
body
|
90 |
+
)
|
91 |
+
st.markdown(style,unsafe_allow_html=True)
|
92 |
+
|
93 |
+
for arg in args:
|
94 |
+
if isinstance(arg, str):
|
95 |
+
body(arg)
|
96 |
+
|
97 |
+
elif isinstance(arg, HtmlElement):
|
98 |
+
body(arg)
|
99 |
+
|
100 |
+
st.markdown(str(foot), unsafe_allow_html=True)
|
101 |
+
|
102 |
+
|
103 |
+
def footer():
|
104 |
+
myargs = [
|
105 |
+
"©️ surendraKumar",
|
106 |
+
br(),
|
107 |
+
link("https://www.linkedin.com/in/surendra-kumar-51802022b", image('https://icons.getbootstrap.com/assets/icons/linkedin.svg') ),
|
108 |
+
br(),
|
109 |
+
link("https://www.instagram.com/im_surendra_dhaka/",image('https://icons.getbootstrap.com/assets/icons/instagram.svg')),
|
110 |
+
]
|
111 |
+
layout(*myargs)
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
footer()
|