Spaces:
Runtime error
Runtime error
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
import gradio as gr | |
import spaces | |
import torch | |
tokenizer = AutoTokenizer.from_pretrained("merve/chatgpt-prompt-generator-v12") | |
model = AutoModelForSeq2SeqLM.from_pretrained("merve/chatgpt-prompt-generator-v12", from_tf=True) | |
device = "cuda" if torch.cuda.is_available() else "cpu" | |
model.to(device) | |
def generate(prompt): | |
batch = tokenizer(prompt, return_tensors="pt") | |
batch.to(device) | |
generated_ids = model.generate(batch["input_ids"], max_new_tokens=150) | |
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True) | |
return output[0] | |
input_component = gr.Textbox(label = "Input a persona, e.g. photographer", value = "photographer") | |
output_component = gr.Textbox(label = "Prompt") | |
examples = [["photographer"], ["developer"]] | |
description = "This app generates ChatGPT prompts, it's based on a BART model trained on [this dataset](https://huggingface.co./datasets/fka/awesome-chatgpt-prompts). π Simply enter a persona that you want the prompt to be generated based on. π§π»π§π»βππ§π»βπ¨π§π»βπ¬π§π»βπ»π§πΌβπ«π§π½βπΎ" | |
gr.Interface(generate, inputs = input_component, outputs=output_component, examples=examples, title = "π¨π»βπ€ ChatGPT Prompt Generator v12 π¨π»βπ€", description=description).launch() | |