Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ from crewai import Agent, Task, Crew, Process
|
|
3 |
from crewai_tools import WebsiteSearchTool
|
4 |
from dotenv import load_dotenv
|
5 |
import os
|
6 |
-
from io import BytesIO # To handle in-memory files
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
@@ -97,10 +96,6 @@ if generate_blog:
|
|
97 |
with st.spinner("Processing tasks..."):
|
98 |
result = crew.kickoff(inputs={'topic': news_link})
|
99 |
|
100 |
-
# Inspect result attributes for debugging
|
101 |
-
st.subheader("Result Attributes")
|
102 |
-
st.write(dir(result))
|
103 |
-
|
104 |
# Access task outputs
|
105 |
try:
|
106 |
task_outputs = result.tasks_output
|
@@ -108,12 +103,6 @@ if generate_blog:
|
|
108 |
st.error("The result object does not have 'tasks_output'.")
|
109 |
task_outputs = []
|
110 |
|
111 |
-
# Display task outputs
|
112 |
-
st.subheader("Task Outputs")
|
113 |
-
for idx, task_output in enumerate(task_outputs):
|
114 |
-
st.write(f"Task {idx + 1}:")
|
115 |
-
st.json(task_output)
|
116 |
-
|
117 |
# Extract blog content
|
118 |
try:
|
119 |
blog_content = task_outputs[1].raw
|
@@ -124,31 +113,20 @@ if generate_blog:
|
|
124 |
st.subheader("Generated Blog")
|
125 |
st.text_area("Blog Content", value=blog_content, height=400)
|
126 |
|
127 |
-
# Actions to save
|
128 |
st.subheader("Actions")
|
129 |
-
save_blog = st.button("Save Blog
|
130 |
-
reject_blog = st.button("Reject Blog")
|
131 |
|
132 |
if save_blog:
|
133 |
try:
|
134 |
-
# Save Markdown content
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
# Provide download button
|
140 |
-
st.download_button(
|
141 |
-
label="Download Blog as Markdown",
|
142 |
-
data=markdown_buffer,
|
143 |
-
file_name="generated_blog.md",
|
144 |
-
mime="text/markdown"
|
145 |
-
)
|
146 |
-
st.success("Blog saved as Markdown and ready for download!")
|
147 |
-
except Exception as e:
|
148 |
-
st.error(f"Failed to save blog as Markdown: {e}")
|
149 |
|
150 |
-
|
151 |
-
|
|
|
152 |
|
153 |
except Exception as e:
|
154 |
st.error(f"An error occurred during the process: {e}")
|
|
|
3 |
from crewai_tools import WebsiteSearchTool
|
4 |
from dotenv import load_dotenv
|
5 |
import os
|
|
|
6 |
|
7 |
# Load environment variables
|
8 |
load_dotenv()
|
|
|
96 |
with st.spinner("Processing tasks..."):
|
97 |
result = crew.kickoff(inputs={'topic': news_link})
|
98 |
|
|
|
|
|
|
|
|
|
99 |
# Access task outputs
|
100 |
try:
|
101 |
task_outputs = result.tasks_output
|
|
|
103 |
st.error("The result object does not have 'tasks_output'.")
|
104 |
task_outputs = []
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
# Extract blog content
|
107 |
try:
|
108 |
blog_content = task_outputs[1].raw
|
|
|
113 |
st.subheader("Generated Blog")
|
114 |
st.text_area("Blog Content", value=blog_content, height=400)
|
115 |
|
116 |
+
# Actions to save the blog
|
117 |
st.subheader("Actions")
|
118 |
+
save_blog = st.button("Save Blog Locally")
|
|
|
119 |
|
120 |
if save_blog:
|
121 |
try:
|
122 |
+
# Save Markdown content to a local file
|
123 |
+
file_path = "generated_blog.md"
|
124 |
+
with open(file_path, "w") as markdown_file:
|
125 |
+
markdown_file.write(blog_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
+
st.success(f"Blog saved successfully as '{file_path}' on your local machine!")
|
128 |
+
except Exception as e:
|
129 |
+
st.error(f"Failed to save blog locally: {e}")
|
130 |
|
131 |
except Exception as e:
|
132 |
st.error(f"An error occurred during the process: {e}")
|