irshadtech10 commited on
Commit
af729f8
·
verified ·
1 Parent(s): bb8a199

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -32
app.py CHANGED
@@ -4,17 +4,14 @@ from dotenv import load_dotenv
4
  from crewai import Agent, Task, Crew, Process
5
  from crewai_tools import SerperDevTool
6
  from langchain_openai import ChatOpenAI
7
- import markdown
8
-
9
- def convert_markdown_to_html(markdown_text):
10
- return markdown.markdown(markdown_text)
11
 
12
  load_dotenv()
13
  SERPER_API_KEY = os.getenv("SERPER_API_KEY")
14
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
15
 
16
  llm = ChatOpenAI(api_key=OPENAI_API_KEY, model='gpt-4o-mini')
17
-
18
  search_tool = SerperDevTool()
19
  def write_social_media_post(user_input):
20
  social_media_writer = Agent(
@@ -53,16 +50,7 @@ def write_blog_post(user_input):
53
  allow_delegation=True,
54
  tools=[search_tool],
55
  llm=llm
56
- )
57
-
58
- blog_post_reviewer = Agent(
59
- role='Blog Reviewer',
60
- goal="Review the blog post for quality, coherence, and accuracy.",
61
- backstory="You have a keen eye for detail and ensure content is of high quality.",
62
- verbose=True,
63
- allow_delegation=True,
64
- llm = llm
65
- )
66
 
67
  blog_writer_task = Task(
68
  description=f"Write a blog article on the topic of '{user_input}' that includes sections such as introduction, body (with subheadings), conclusion, and sources cited at the end. Generate the blog in both Swedish and English.",
@@ -70,15 +58,9 @@ def write_blog_post(user_input):
70
  agent=blog_post_writer,
71
  )
72
 
73
- blog_post_reviewer_task = Task(
74
- description="Review the blog post for quality, and coherence.",
75
- expected_output="A reviewed blog post with necessary corrections.",
76
- agent=blog_post_reviewer,
77
- )
78
-
79
  crew = Crew(
80
- tasks=[blog_writer_task, blog_post_reviewer_task],
81
- agents=[blog_post_writer, blog_post_reviewer],
82
  verbose=True,
83
  process=Process.sequential,
84
  )
@@ -138,18 +120,15 @@ user_input = st.text_area("Enter the topic or information for your content:")
138
  if st.button("Generate Content"):
139
  if option == "Social Media Agent":
140
  result = write_social_media_post(user_input)
141
- html_output = convert_markdown_to_html(result)
142
- st.markdown(html_output, unsafe_allow_html=True)
143
- #st.write(result)
144
  elif option == "Blog Article Agent":
145
  result = write_blog_post(user_input)
146
- html_output = convert_markdown_to_html(result)
147
- st.markdown(html_output, unsafe_allow_html=True)
148
- #st.write(result)
149
  elif option == "Compose Agent":
150
  result = write_blog_post_from_info(user_input)
151
- html_output = convert_markdown_to_html(result)
152
- st.markdown(html_output, unsafe_allow_html=True)
153
- #st.write(result)
154
  else:
155
  st.write("Please select a valid option.")
 
4
  from crewai import Agent, Task, Crew, Process
5
  from crewai_tools import SerperDevTool
6
  from langchain_openai import ChatOpenAI
7
+ from langchain_core.output_parsers import StrOutputParser
 
 
 
8
 
9
  load_dotenv()
10
  SERPER_API_KEY = os.getenv("SERPER_API_KEY")
11
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12
 
13
  llm = ChatOpenAI(api_key=OPENAI_API_KEY, model='gpt-4o-mini')
14
+ output_parser = StrOutputParser()
15
  search_tool = SerperDevTool()
16
  def write_social_media_post(user_input):
17
  social_media_writer = Agent(
 
50
  allow_delegation=True,
51
  tools=[search_tool],
52
  llm=llm
53
+ )
 
 
 
 
 
 
 
 
 
54
 
55
  blog_writer_task = Task(
56
  description=f"Write a blog article on the topic of '{user_input}' that includes sections such as introduction, body (with subheadings), conclusion, and sources cited at the end. Generate the blog in both Swedish and English.",
 
58
  agent=blog_post_writer,
59
  )
60
 
 
 
 
 
 
 
61
  crew = Crew(
62
+ tasks=[blog_writer_task],
63
+ agents=[blog_post_writer],
64
  verbose=True,
65
  process=Process.sequential,
66
  )
 
120
  if st.button("Generate Content"):
121
  if option == "Social Media Agent":
122
  result = write_social_media_post(user_input)
123
+ output = output_parser.parse(result)
124
+ st.write(output)
 
125
  elif option == "Blog Article Agent":
126
  result = write_blog_post(user_input)
127
+ output = output_parser.parse(result)
128
+ st.write(output)
 
129
  elif option == "Compose Agent":
130
  result = write_blog_post_from_info(user_input)
131
+ output = output_parser.parse(result)
132
+ st.write(output)
 
133
  else:
134
  st.write("Please select a valid option.")