Spaces:
Running
Running
import gradio as gr | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
# Load the model and tokenizer | |
model_name = "Qwen/Qwen1.5-7B" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
def generate_article(topic): | |
inputs = tokenizer(f"Generate article for the NY times tweet {topic}", return_tensors="pt") | |
outputs = model.generate(inputs['input_ids'], max_new_tokens=512, temperature=0.5) | |
return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=generate_article, | |
inputs="text", | |
outputs="text", | |
title="Article Generator", | |
description="Generate an article for a given topic." | |
) | |
# Launch the Gradio app | |
iface.launch() |