import streamlit as st from transformers import pipeline # Set the page configuration st.set_page_config( page_title="News Report Generator", layout="centered", initial_sidebar_state="auto", ) # Load the model with caching to improve performance @st.cache_resource def load_model(): model_name = "gpt2" # Change to a larger model for more advanced outputs if needed return pipeline("text-generation", model=model_name) text_generator = load_model() # Streamlit app UI st.title("📰 News Report Generator") st.markdown("Generate a compelling news report based on any given scenario.") # Input for the scenario and word count scenario = st.text_area( "📜 Enter the Scenario:", placeholder="Describe the scenario for the news report...", height=150, ) word_count = st.number_input( "🔢 Desired Word Count:", min_value=50, max_value=1000, step=50, help="Specify the approximate number of words for the generated report.", ) # Generate News Report button if st.button("📝 Generate News Report"): if not scenario.strip(): st.error("❌ Please provide a scenario to generate the news report.") else: with st.spinner("Generating your news report..."): try: # Generate the news report prompt = f"Write a news report on the following scenario: {scenario}\n\n" generated_text = text_generator(prompt, max_length=int(word_count), num_return_sequences=1) # Display the result st.subheader("📰 Generated News Report") st.text_area("Report", value=generated_text[0]["generated_text"], height=400) except Exception as e: st.error(f"❌ An error occurred: {e}")