Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import transformers
|
2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
+
from transformers import GenerationConfig
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
model_name = "gpt2-large"
|
7 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
8 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
title = st.text_area("\nEnter a title to generate a blog post:")
|
11 |
+
|
12 |
+
input_prompt = f"Blog Title: {title}\n\nBlog Post:\n"
|
13 |
+
input_ids = tokenizer.encode(input_prompt, return_tensors='pt')
|
14 |
+
|
15 |
+
generation_config = GenerationConfig(max_new_tokens=100, do_sample=True, temperature=0.7)
|
16 |
+
|
17 |
+
output_ids = model.generate(input_ids, generation_config=generation_config)[0]
|
18 |
+
|
19 |
+
output_text = tokenizer.decode(output_ids, skip_special_tokens=True)
|
20 |
+
|
21 |
+
if text:
|
22 |
+
st.write(output_text)
|