File size: 976 Bytes
601256e
88301ec
601256e
88301ec
601256e
 
 
 
88301ec
601256e
 
88301ec
601256e
88301ec
 
 
 
 
601256e
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Set up the Hugging Face API token
HF_token = "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"

# Load the tokenizer and model
model_name = "Qwen/Qwen1.5-7B"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HF_token)
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=HF_token)

# Function to generate article
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)

# Streamlit app interface
st.title("Article Generator")
topic = st.text_input("Enter a topic:")
if st.button("Generate"):
    if topic:
        article = generate_article(topic)
        st.write(article)
    else:
        st.write("Please enter a topic.")