File size: 780 Bytes
88301ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()