rairo commited on
Commit
a3b8cac
·
verified ·
1 Parent(s): cb9d1ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -10,6 +10,8 @@ import PyPDF2
10
  import os
11
  import json
12
  from dotenv import load_dotenv
 
 
13
 
14
  # Load environment variables
15
  load_dotenv()
@@ -44,12 +46,21 @@ class SmartShoppingAssistant:
44
  )
45
  ]
46
 
47
- prompt = "You are a shopping assistant. Use the tools provided to find products based on user queries."
 
 
 
 
48
 
 
 
 
 
 
49
  agent = create_openai_functions_agent(
50
- llm=llm_flash_exp,
51
  tools=tools,
52
- prompt=prompt
53
  )
54
 
55
  self.agent_executor = AgentExecutor(
@@ -85,21 +96,6 @@ class SmartShoppingAssistant:
85
  return "\n\n".join(results) if results else "No matching products found."
86
  except Exception as e:
87
  return f"Error processing query: {str(e)}"
88
-
89
- def extract_text_from_image(self, image):
90
- try:
91
- response = model_flash_think.generate_content(image)
92
- return response.text
93
- except Exception as e:
94
- return f"Error processing image: {str(e)}"
95
-
96
- def extract_text_from_pdf(self, pdf_file):
97
- try:
98
- pdf_reader = PyPDF2.PdfReader(pdf_file)
99
- text = "".join([page.extract_text() for page in pdf_reader.pages])
100
- return text
101
- except Exception as e:
102
- return f"Error processing PDF: {str(e)}"
103
 
104
  def main():
105
  st.set_page_config(page_title="Smart Shopping Assistant", layout="wide")
 
10
  import os
11
  import json
12
  from dotenv import load_dotenv
13
+ from langchain.chains import LLMChain
14
+ from langchain.prompts import PromptTemplate
15
 
16
  # Load environment variables
17
  load_dotenv()
 
46
  )
47
  ]
48
 
49
+ # Define a prompt template for the agent
50
+ prompt_template = """
51
+ You are a shopping assistant. Use the tools provided to find products based on user queries.
52
+ {input}
53
+ """
54
 
55
+ # Create a PromptTemplate and LLMChain to make the model compatible
56
+ prompt = PromptTemplate(input_variables=["input"], template=prompt_template)
57
+ llm_chain = LLMChain(llm=llm_flash_exp, prompt=prompt)
58
+
59
+ # Create the agent with the adapted chain
60
  agent = create_openai_functions_agent(
61
+ llm=llm_chain,
62
  tools=tools,
63
+ prompt=prompt_template
64
  )
65
 
66
  self.agent_executor = AgentExecutor(
 
96
  return "\n\n".join(results) if results else "No matching products found."
97
  except Exception as e:
98
  return f"Error processing query: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  def main():
101
  st.set_page_config(page_title="Smart Shopping Assistant", layout="wide")