Spaces:
Runtime error
Runtime error
ashiqabdulkhader
commited on
Commit
•
f389cad
1
Parent(s):
6748f37
inital push
Browse files- app.py +31 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# streamlit for gpt2 model web app
|
2 |
+
import streamlit as st
|
3 |
+
import tensorflow as tf
|
4 |
+
from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
|
5 |
+
|
6 |
+
tokenizer = GPT2Tokenizer.from_pretrained("ashiqabdulkhader/GPT2-Poet")
|
7 |
+
model = TFGPT2LMHeadModel.from_pretrained("ashiqabdulkhader/GPT2-Poet")
|
8 |
+
|
9 |
+
st.title("GPT2 Poet")
|
10 |
+
st.write("This is a web app for GPT2 Poet model. You can generate poems using this web app.")
|
11 |
+
|
12 |
+
prompt = st.text_input("Enter a prompt for the poem", "The quick brown fox")
|
13 |
+
length = st.slider("Length of the poem", min_value=100,
|
14 |
+
max_value=1000, value=100)
|
15 |
+
temperature = st.slider("Temperature", min_value=0.0, max_value=1.0, value=1.0)
|
16 |
+
top_k = st.slider("Top K", min_value=0, max_value=10, value=0)
|
17 |
+
top_p = st.slider("Top P", min_value=0.0, max_value=1.0, value=0.9)
|
18 |
+
|
19 |
+
input_ids = tokenizer.encode(prompt, return_tensors='tf')
|
20 |
+
sample_outputs = model.generate(
|
21 |
+
input_ids,
|
22 |
+
do_sample=True,
|
23 |
+
max_length=length,
|
24 |
+
top_k=top_k,
|
25 |
+
top_p=top_p,
|
26 |
+
temperature=temperature,
|
27 |
+
num_return_sequences=3
|
28 |
+
)
|
29 |
+
|
30 |
+
st.write("Output:", tokenizer.decode(
|
31 |
+
sample_outputs[0], skip_special_tokens=True))
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
tensorflow
|