Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,20 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
+
# Define model and tokenizer
|
5 |
+
model_name = 'openai-community/gpt2-large'
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
|
8 |
|
9 |
+
def generate_blogpost(topic):
|
10 |
+
inputs = tokenizer.encode(topic, return_tensors='pt')
|
11 |
+
outputs = model.generate(inputs, max_length=500, num_return_sequences=1)
|
12 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
return text
|
14 |
+
|
15 |
+
# Streamlit app
|
16 |
+
st.title('Blog Post Generator')
|
17 |
+
topic = st.text_input('Enter a topic:')
|
18 |
+
if topic:
|
19 |
+
blogpost = generate_blogpost(topic)
|
20 |
+
st.write(blogpost)
|