Spaces:
Runtime error
Runtime error
Commit
·
cde0874
1
Parent(s):
b61d13d
add files
Browse files- app.py +38 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
st.title("AI text-gen Web-app")
|
5 |
+
st.write("This is a auto-complete/text generation web-app powered by GPT-neo. GPT-Neo 125M is a transformer model designed using EleutherAI's replication of the GPT-3 architecture. GPT-Neo refers to the class of models, while 125M represents the number of parameters of this particular pre-trained model.")
|
6 |
+
|
7 |
+
# instantiate the model / download
|
8 |
+
@st.cache(allow_output_mutation=True)
|
9 |
+
def load_model():
|
10 |
+
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-125M')
|
11 |
+
return (generator)
|
12 |
+
|
13 |
+
generator=load_model()
|
14 |
+
|
15 |
+
min_length=st.slider(
|
16 |
+
'Specify Min length of the text of want to be generated',
|
17 |
+
10, 100, 20)
|
18 |
+
max_length=st.slider(
|
19 |
+
'Specify Max length of the text of want to be generated',
|
20 |
+
20, 150, 30)
|
21 |
+
|
22 |
+
# create a prompt text for the text generation
|
23 |
+
prompt_text = st.text_input(
|
24 |
+
label = "Type some text here and this model will generate more....",
|
25 |
+
value="We live in a society")
|
26 |
+
|
27 |
+
|
28 |
+
if(max_length<=min_length):
|
29 |
+
st.error("max_length cannot be less than equal to min_length")
|
30 |
+
else:
|
31 |
+
with st.spinner("AI is at Work........"):
|
32 |
+
gpt_text = generator(
|
33 |
+
prompt_text,
|
34 |
+
min_length=min_length,
|
35 |
+
max_length=max_length,
|
36 |
+
do_sample=True)[0]["generated_text"]
|
37 |
+
st.success("Successfully generated the below text:")
|
38 |
+
st.write(gpt_text)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch==1.12.0
|
2 |
+
transformers==4.19.4
|
3 |
+
streamlit==1.13.0
|