Asaad Almutareb commited on
Commit
153e9c1
1 Parent(s): 2454aa9

adjust for hf gradio

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app_gui.py +4 -25
  3. rag_app/agents/react_agent.py +6 -15
README.md CHANGED
@@ -3,7 +3,7 @@ title: Insurance Advisor Agents PoC
3
  emoji: 🤖
4
  colorFrom: red
5
  colorTo: indigo
6
- sdk: docker
7
  python: 3.11
8
  app_file: app_gui.py
9
  pinned: false
 
3
  emoji: 🤖
4
  colorFrom: red
5
  colorTo: indigo
6
+ sdk: gradio
7
  python: 3.11
8
  app_file: app_gui.py
9
  pinned: false
app_gui.py CHANGED
@@ -1,12 +1,6 @@
1
  # Import Gradio for UI, along with other necessary libraries
2
  import gradio as gr
3
- from fastapi import FastAPI
4
- from rag_app.agents.react_agent import agent_executor, llm
5
- from rag_app.chains import user_response_sentiment_prompt
6
- # need to import the qa!
7
-
8
- app = FastAPI()
9
- user_sentiment_chain = user_response_sentiment_prompt | llm
10
 
11
 
12
  if __name__ == "__main__":
@@ -21,13 +15,6 @@ if __name__ == "__main__":
21
  def bot(history):
22
  # Obtain the response from the 'infer' function using the latest input
23
  response = infer(history[-1][0], history)
24
- #sources = [doc.metadata.get("source") for doc in response['source_documents']]
25
- #src_list = '\n'.join(sources)
26
- #print_this = response['result'] + "\n\n\n Sources: \n\n\n" + src_list
27
-
28
-
29
- #history[-1][1] = print_this #response['answer']
30
- # Update the history with the bot's response
31
  history[-1][1] = response['output']
32
  return history
33
 
@@ -35,10 +22,6 @@ if __name__ == "__main__":
35
  def infer(question, history):
36
  # Use the question and history to query the RAG model
37
  #result = qa({"query": question, "history": history, "question": question})
38
- try:
39
- data = user_sentiment_chain.invoke({"user_reponse":question})
40
- except Exception as e:
41
- raise e
42
  try:
43
  result = agent_executor.invoke(
44
  {
@@ -46,17 +29,15 @@ if __name__ == "__main__":
46
  "chat_history": history
47
  }
48
  )
49
-
50
-
51
  return result
52
  except Exception:
53
  raise gr.Error("Model is Overloaded, Please retry later!")
54
 
55
  def vote(data: gr.LikeData):
56
  if data.liked:
57
- print("You upvoted this response: " + data.value)
58
  else:
59
- print("You downvoted this response: " + data.value)
60
 
61
  # CSS styling for the Gradio interface
62
  css = """
@@ -94,6 +75,4 @@ if __name__ == "__main__":
94
  clear.click(lambda: None, None, chatbot, queue=False)
95
 
96
  # Launch the Gradio demo interface
97
- demo.queue().launch(share=False, debug=True)
98
-
99
- app = gr.mount_gradio_app(app, demo, path="/")
 
1
  # Import Gradio for UI, along with other necessary libraries
2
  import gradio as gr
3
+ from rag_app.agents.react_agent import agent_executor
 
 
 
 
 
 
4
 
5
 
6
  if __name__ == "__main__":
 
15
  def bot(history):
16
  # Obtain the response from the 'infer' function using the latest input
17
  response = infer(history[-1][0], history)
 
 
 
 
 
 
 
18
  history[-1][1] = response['output']
19
  return history
20
 
 
22
  def infer(question, history):
23
  # Use the question and history to query the RAG model
24
  #result = qa({"query": question, "history": history, "question": question})
 
 
 
 
25
  try:
26
  result = agent_executor.invoke(
27
  {
 
29
  "chat_history": history
30
  }
31
  )
 
 
32
  return result
33
  except Exception:
34
  raise gr.Error("Model is Overloaded, Please retry later!")
35
 
36
  def vote(data: gr.LikeData):
37
  if data.liked:
38
+ print("You upvoted this response: ")
39
  else:
40
+ print("You downvoted this response: ")
41
 
42
  # CSS styling for the Gradio interface
43
  css = """
 
75
  clear.click(lambda: None, None, chatbot, queue=False)
76
 
77
  # Launch the Gradio demo interface
78
+ demo.queue().launch(share=False, debug=True)
 
 
rag_app/agents/react_agent.py CHANGED
@@ -7,17 +7,13 @@ from langchain.agents.output_parsers import ReActJsonSingleInputOutputParser
7
  from langchain.tools.render import render_text_description
8
  import os
9
  from dotenv import load_dotenv
10
- from rag_app.structured_tools.agent_tools import (
11
- web_research, ask_user, get_email
12
  )
13
 
14
  from langchain.prompts import PromptTemplate
15
  from rag_app.templates.react_json_with_memory_ger import template_system
16
  # from innovation_pathfinder_ai.utils import logger
17
- # from langchain.globals import set_llm_cache
18
- # from langchain.cache import SQLiteCache
19
-
20
- # set_llm_cache(SQLiteCache(database_path=".cache.db"))
21
  # logger = logger.get_console_logger("hf_mixtral_agent")
22
 
23
  config = load_dotenv(".env")
@@ -25,10 +21,6 @@ HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
25
  GOOGLE_CSE_ID = os.getenv('GOOGLE_CSE_ID')
26
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
27
  LLM_MODEL = os.getenv('LLM_MODEL')
28
- # LANGCHAIN_TRACING_V2 = "true"
29
- # LANGCHAIN_ENDPOINT = "https://api.smith.langchain.com"
30
- # LANGCHAIN_API_KEY = os.getenv('LANGCHAIN_API_KEY')
31
- # LANGCHAIN_PROJECT = os.getenv('LANGCHAIN_PROJECT')
32
 
33
  # Load the model from the Hugging Face Hub
34
  llm = HuggingFaceEndpoint(repo_id=LLM_MODEL,
@@ -40,11 +32,10 @@ llm = HuggingFaceEndpoint(repo_id=LLM_MODEL,
40
 
41
 
42
  tools = [
43
- #knowledgeBase_search,
44
- #google_search,
45
- web_research,
46
- ask_user,
47
- get_email
48
  ]
49
 
50
  prompt = PromptTemplate.from_template(
 
7
  from langchain.tools.render import render_text_description
8
  import os
9
  from dotenv import load_dotenv
10
+ from rag_app.structured_tools.structured_tools import (
11
+ google_search, knowledgeBase_search
12
  )
13
 
14
  from langchain.prompts import PromptTemplate
15
  from rag_app.templates.react_json_with_memory_ger import template_system
16
  # from innovation_pathfinder_ai.utils import logger
 
 
 
 
17
  # logger = logger.get_console_logger("hf_mixtral_agent")
18
 
19
  config = load_dotenv(".env")
 
21
  GOOGLE_CSE_ID = os.getenv('GOOGLE_CSE_ID')
22
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
23
  LLM_MODEL = os.getenv('LLM_MODEL')
 
 
 
 
24
 
25
  # Load the model from the Hugging Face Hub
26
  llm = HuggingFaceEndpoint(repo_id=LLM_MODEL,
 
32
 
33
 
34
  tools = [
35
+ knowledgeBase_search,
36
+ google_search,
37
+ #web_research,
38
+ #ask_user
 
39
  ]
40
 
41
  prompt = PromptTemplate.from_template(