pratikshahp commited on
Commit
3934a61
·
verified ·
1 Parent(s): bc84740

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import os
2
  from dotenv import load_dotenv
3
  import gradio as gr
4
- from langchain_core.prompts import PromptTemplate,ChatPromptTemplate
5
  from langchain_huggingface import HuggingFaceEndpoint
6
  from langchain_core.output_parsers import StrOutputParser
7
-
8
 
9
  # Load environment variables
10
  load_dotenv()
@@ -27,16 +27,17 @@ Make sure the blog post is informative, engaging, and well-structured.
27
  """
28
 
29
  # Create a prompt template instance
30
- blog_prompt_template = ChatPromptTemplate.from_template(template=TEMPLATE)
31
 
32
- # Initialize the LLMChain with the HuggingFace model and prompt template
33
- blog_chain = blog_prompt_template | model | StrOutputParser()
 
 
34
 
35
- def generate_blog_post(topic: str, author_name: str) -> str:
36
  if topic:
37
  # Generate the blog post
38
  blog_post = blog_chain.invoke({"topic": topic})
39
-
40
  return blog_post
41
  else:
42
  return "Please enter a topic for the blog post."
 
1
  import os
2
  from dotenv import load_dotenv
3
  import gradio as gr
4
+ from langchain_core.prompts import PromptTemplate
5
  from langchain_huggingface import HuggingFaceEndpoint
6
  from langchain_core.output_parsers import StrOutputParser
7
+ from langchain_core.runnables import RunnableSequence
8
 
9
  # Load environment variables
10
  load_dotenv()
 
27
  """
28
 
29
  # Create a prompt template instance
30
+ blog_prompt_template = PromptTemplate(input_variables=["topic"], template=TEMPLATE)
31
 
32
+ # Initialize the sequence using RunnableSequence
33
+ blog_chain = RunnableSequence(
34
+ llm | blog_prompt_template | StrOutputParser()
35
+ )
36
 
37
+ def generate_blog_post(topic: str) -> str:
38
  if topic:
39
  # Generate the blog post
40
  blog_post = blog_chain.invoke({"topic": topic})
 
41
  return blog_post
42
  else:
43
  return "Please enter a topic for the blog post."