Spaces:
Runtime error
Runtime error
File size: 1,224 Bytes
aa49290 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel
import streamlit as st
# Load the tokenizer and model
tokenizer = GPT2Tokenizer.from_pretrained('webtoon_tokenizer')
model = GPT2LMHeadModel.from_pretrained('webtoon_model')
# Define the app
def main():
st.title('Webtoon Description Generator')
# Get the input from the user
title = st.text_input('Enter the title of the Webtoon:', '')
# Generate the description
if st.button('Generate Description'):
with st.spinner('Generating...'):
description = generate_description(title)
st.success(description)
# Define the function that generates the description
def generate_description(title):
# Preprocess the input
input_text = f"{title.lower()}"
input_ids = tokenizer.encode(input_text, return_tensors='pt')
# Generate the output using the model
output = model.generate(
input_ids=input_ids,
max_length=256,
num_beams=4,
early_stopping=True,
no_repeat_ngram_size=2
)
# Convert the output to text
description = tokenizer.decode(output[0], skip_special_tokens=True)
return description
if __name__ == '__main__':
main()
|