Spaces:
Sleeping
Sleeping
Saanvi12011
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Set the page configuration
|
5 |
+
st.set_page_config(
|
6 |
+
page_title="News Report Generator",
|
7 |
+
layout="centered",
|
8 |
+
initial_sidebar_state="auto",
|
9 |
+
)
|
10 |
+
|
11 |
+
# Load the model with caching to improve performance
|
12 |
+
@st.cache_resource
|
13 |
+
def load_model():
|
14 |
+
model_name = "gpt2" # Change to a larger model for more advanced outputs if needed
|
15 |
+
return pipeline("text-generation", model=model_name)
|
16 |
+
|
17 |
+
text_generator = load_model()
|
18 |
+
|
19 |
+
# Streamlit app UI
|
20 |
+
st.title("π° News Report Generator")
|
21 |
+
st.markdown("Generate a compelling news report based on any given scenario.")
|
22 |
+
|
23 |
+
# Input for the scenario and word count
|
24 |
+
scenario = st.text_area(
|
25 |
+
"π Enter the Scenario:",
|
26 |
+
placeholder="Describe the scenario for the news report...",
|
27 |
+
height=150,
|
28 |
+
)
|
29 |
+
word_count = st.number_input(
|
30 |
+
"π’ Desired Word Count:",
|
31 |
+
min_value=50,
|
32 |
+
max_value=1000,
|
33 |
+
step=50,
|
34 |
+
help="Specify the approximate number of words for the generated report.",
|
35 |
+
)
|
36 |
+
|
37 |
+
# Generate News Report button
|
38 |
+
if st.button("π Generate News Report"):
|
39 |
+
if not scenario.strip():
|
40 |
+
st.error("β Please provide a scenario to generate the news report.")
|
41 |
+
else:
|
42 |
+
with st.spinner("Generating your news report..."):
|
43 |
+
try:
|
44 |
+
# Generate the news report
|
45 |
+
prompt = f"Write a news report on the following scenario: {scenario}\n\n"
|
46 |
+
generated_text = text_generator(prompt, max_length=int(word_count), num_return_sequences=1)
|
47 |
+
|
48 |
+
# Display the result
|
49 |
+
st.subheader("π° Generated News Report")
|
50 |
+
st.text_area("Report", value=generated_text[0]["generated_text"], height=400)
|
51 |
+
except Exception as e:
|
52 |
+
st.error(f"β An error occurred: {e}")
|