Update app.py
Browse files
app.py
CHANGED
@@ -37,21 +37,21 @@ def generate_pdf_download(content, filename="generated_blog.pdf"):
|
|
37 |
st.title("SmolAgents Content Writer")
|
38 |
|
39 |
# Tabs for the interface
|
40 |
-
tabs = st.tabs(["
|
41 |
|
42 |
-
# Tab 1:
|
43 |
with tabs[0]:
|
44 |
-
|
45 |
st.write("Generate high-quality blog content enriched with real-time insights using SmolAgents.")
|
46 |
|
47 |
# Input field for blog topic or prompt
|
48 |
-
blog_prompt = st.text_area("Enter your blog topic or prompt:", placeholder="E.g., The Future of
|
49 |
|
50 |
# Input field for choosing content tone
|
51 |
tone = st.selectbox("Choose the tone of the content:", ["Professional", "Casual", "Persuasive", "Informative"])
|
52 |
|
53 |
# Option to include a summary
|
54 |
-
|
55 |
|
56 |
# Button to trigger blog content generation
|
57 |
if st.button("Generate Blog Content"):
|
@@ -68,57 +68,48 @@ with tabs[0]:
|
|
68 |
blog_result = content_agent.run(agent_prompt)
|
69 |
|
70 |
# Display the generated blog content
|
71 |
-
|
72 |
st.write(blog_result)
|
73 |
|
74 |
-
#
|
75 |
-
st.session_state["last_content"] = blog_result
|
76 |
-
|
77 |
-
# Generate a summary if requested
|
78 |
if include_summary:
|
79 |
summary_prompt = (
|
80 |
f"Provide a concise and well-ordered summary of the following content with key points as bullet points:\n"
|
81 |
f"{blog_result}"
|
82 |
)
|
83 |
summary_result = content_agent.run(summary_prompt)
|
84 |
-
st.
|
|
|
|
|
|
|
|
|
85 |
except Exception as e:
|
86 |
st.error("An error occurred while generating content. Please try again.")
|
87 |
else:
|
88 |
st.warning("Please enter a valid blog topic or prompt.")
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
if "last_content" in st.session_state:
|
92 |
content = st.session_state["last_content"]
|
|
|
|
|
93 |
text_file_path, text_filename = generate_text_download(content)
|
94 |
with open(text_file_path, "rb") as file:
|
95 |
-
st.download_button(label="Download
|
|
|
|
|
96 |
pdf_file_path, pdf_filename = generate_pdf_download(content)
|
97 |
with open(pdf_file_path, "rb") as file:
|
98 |
-
st.download_button(label="Download
|
99 |
-
|
100 |
-
# Tab 2: Generated Summary
|
101 |
-
with tabs[1]:
|
102 |
-
#st.header("Generated Summary")
|
103 |
-
if "last_summary" in st.session_state:
|
104 |
-
st.subheader("Content Summary")
|
105 |
-
st.markdown(st.session_state["last_summary"])
|
106 |
-
|
107 |
-
# Download option for summary
|
108 |
-
summary = st.session_state["last_summary"]
|
109 |
-
summary_text_file_path, summary_text_filename = generate_text_download(summary, filename="generated_summary.txt")
|
110 |
-
with open(summary_text_file_path, "rb") as file:
|
111 |
-
st.download_button(label="Download Summary as Text File", data=file, file_name=summary_text_filename, mime="text/plain")
|
112 |
-
summary_pdf_file_path, summary_pdf_filename = generate_pdf_download(summary, filename="generated_summary.pdf")
|
113 |
-
with open(summary_pdf_file_path, "rb") as file:
|
114 |
-
st.download_button(label="Download Summary as PDF", data=file, file_name=summary_pdf_filename, mime="application/pdf")
|
115 |
-
else:
|
116 |
-
st.write("No summary available. Generate content and include a summary to view it here.")
|
117 |
-
|
118 |
-
# Tab 3: Agent Activity
|
119 |
-
with tabs[2]:
|
120 |
-
st.header("Agent Activity")
|
121 |
-
if "last_content" in st.session_state:
|
122 |
-
display_agent_activity(blog_prompt, st.session_state["last_content"])
|
123 |
else:
|
124 |
-
st.write("No
|
|
|
37 |
st.title("SmolAgents Content Writer")
|
38 |
|
39 |
# Tabs for the interface
|
40 |
+
tabs = st.tabs(["Generate Content", "Agent Activity", "Download Options"])
|
41 |
|
42 |
+
# Tab 1: Generate Content
|
43 |
with tabs[0]:
|
44 |
+
st.header("Generate Content")
|
45 |
st.write("Generate high-quality blog content enriched with real-time insights using SmolAgents.")
|
46 |
|
47 |
# Input field for blog topic or prompt
|
48 |
+
blog_prompt = st.text_area("Enter your blog topic or prompt:", placeholder="E.g., The Future of AI in Healthcare")
|
49 |
|
50 |
# Input field for choosing content tone
|
51 |
tone = st.selectbox("Choose the tone of the content:", ["Professional", "Casual", "Persuasive", "Informative"])
|
52 |
|
53 |
# Option to include a summary
|
54 |
+
include_summary = st.checkbox("Include a summary of the generated content")
|
55 |
|
56 |
# Button to trigger blog content generation
|
57 |
if st.button("Generate Blog Content"):
|
|
|
68 |
blog_result = content_agent.run(agent_prompt)
|
69 |
|
70 |
# Display the generated blog content
|
71 |
+
st.subheader("Generated Blog Content")
|
72 |
st.write(blog_result)
|
73 |
|
74 |
+
# Display a summary if requested
|
|
|
|
|
|
|
75 |
if include_summary:
|
76 |
summary_prompt = (
|
77 |
f"Provide a concise and well-ordered summary of the following content with key points as bullet points:\n"
|
78 |
f"{blog_result}"
|
79 |
)
|
80 |
summary_result = content_agent.run(summary_prompt)
|
81 |
+
st.subheader("Content Summary")
|
82 |
+
st.markdown(summary_result)
|
83 |
+
|
84 |
+
# Store result for download
|
85 |
+
st.session_state["last_content"] = blog_result
|
86 |
except Exception as e:
|
87 |
st.error("An error occurred while generating content. Please try again.")
|
88 |
else:
|
89 |
st.warning("Please enter a valid blog topic or prompt.")
|
90 |
|
91 |
+
# Tab 2: Agent Activity
|
92 |
+
with tabs[1]:
|
93 |
+
st.header("Agent Activity")
|
94 |
+
if "last_content" in st.session_state:
|
95 |
+
display_agent_activity(blog_prompt, st.session_state["last_content"])
|
96 |
+
else:
|
97 |
+
st.write("No recent activity to display.")
|
98 |
+
|
99 |
+
# Tab 3: Download Options
|
100 |
+
with tabs[2]:
|
101 |
+
st.header("Download Options")
|
102 |
if "last_content" in st.session_state:
|
103 |
content = st.session_state["last_content"]
|
104 |
+
|
105 |
+
# Text file download
|
106 |
text_file_path, text_filename = generate_text_download(content)
|
107 |
with open(text_file_path, "rb") as file:
|
108 |
+
st.download_button(label="Download as Text File", data=file, file_name=text_filename, mime="text/plain")
|
109 |
+
|
110 |
+
# PDF file download
|
111 |
pdf_file_path, pdf_filename = generate_pdf_download(content)
|
112 |
with open(pdf_file_path, "rb") as file:
|
113 |
+
st.download_button(label="Download as PDF", data=file, file_name=pdf_filename, mime="application/pdf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
else:
|
115 |
+
st.write("No content available for download. Generate content first.")
|