PabloVD commited on
Commit
3ad9a49
1 Parent(s): e19a241

Customize graphical UI:

Browse files

- Include avatars
- Include greetings message
- Improve readability

Files changed (3) hide show
  1. app.py +22 -3
  2. ims/camelslogo.jpg +0 -0
  3. ims/userpic.png +0 -0
app.py CHANGED
@@ -1,4 +1,6 @@
1
- # https://python.langchain.com/docs/tutorials/rag/
 
 
2
  import gradio as gr
3
  from langchain import hub
4
  from langchain_chroma import Chroma
@@ -50,6 +52,8 @@ urls = get_subpages(base_url)
50
  loader = WebBaseLoader(urls)
51
  docs = loader.load()
52
 
 
 
53
  # Join content pages for processing
54
  def format_docs(docs):
55
  return "\n\n".join(doc.page_content for doc in docs)
@@ -91,6 +95,7 @@ embeddings = HuggingFaceInstructEmbeddings(model_name=embed_model)
91
  # RAG chain
92
  rag_chain = RAG(llm, docs, embeddings)
93
 
 
94
  def handle_prompt(message, history):
95
  try:
96
  # Stream output
@@ -101,7 +106,9 @@ def handle_prompt(message, history):
101
  except:
102
  raise gr.Error("Requests rate limit exceeded")
103
 
104
- greetingsmessage = "Hi, I'm the CAMELS DocBot, I'm here to assist you with any question related to the CAMELS simulations documentation"
 
 
105
  example_questions = [
106
  "How can I read a halo file?",
107
  "Which simulation suites are included in CAMELS?",
@@ -109,7 +116,19 @@ example_questions = [
109
  "Write a complete snippet of code getting the power spectrum of a simulation"
110
  ]
111
 
 
 
 
 
 
 
112
  # Define Gradio interface
113
- demo = gr.ChatInterface(handle_prompt, type="messages", title="CAMELS DocBot", examples=example_questions, theme=gr.themes.Soft(), description=greetingsmessage)#, chatbot=chatbot)
 
 
 
 
 
 
114
 
115
  demo.launch()
 
1
+ # AI assistant with a RAG system to query information from the CAMELS cosmological simulations using Langchain
2
+ # Author: Pablo Villanueva Domingo
3
+
4
  import gradio as gr
5
  from langchain import hub
6
  from langchain_chroma import Chroma
 
52
  loader = WebBaseLoader(urls)
53
  docs = loader.load()
54
 
55
+ print("Pages loaded:",len(docs))
56
+
57
  # Join content pages for processing
58
  def format_docs(docs):
59
  return "\n\n".join(doc.page_content for doc in docs)
 
95
  # RAG chain
96
  rag_chain = RAG(llm, docs, embeddings)
97
 
98
+ # Function to handle prompt and query the RAG chain
99
  def handle_prompt(message, history):
100
  try:
101
  # Stream output
 
106
  except:
107
  raise gr.Error("Requests rate limit exceeded")
108
 
109
+ # Predefined messages and examples
110
+ description = "AI powered assistant which answers any question related to the [CAMELS simulations](https://www.camel-simulations.org/)."
111
+ greetingsmessage = "Hi, I'm the CAMELS DocBot, I'm here to assist you with any question related to the CAMELS simulations."
112
  example_questions = [
113
  "How can I read a halo file?",
114
  "Which simulation suites are included in CAMELS?",
 
116
  "Write a complete snippet of code getting the power spectrum of a simulation"
117
  ]
118
 
119
+ # Define customized Gradio chatbot
120
+ chatbot = gr.Chatbot([{"role":"assistant", "content":greetingsmessage}],
121
+ type="messages",
122
+ avatar_images=["ims/userpic.png","ims/camelslogo.jpg"],
123
+ height="60vh")
124
+
125
  # Define Gradio interface
126
+ demo = gr.ChatInterface(handle_prompt,
127
+ type="messages",
128
+ title="CAMELS DocBot",
129
+ examples=example_questions,
130
+ theme=gr.themes.Soft(),
131
+ description=description,
132
+ chatbot=chatbot)
133
 
134
  demo.launch()
ims/camelslogo.jpg ADDED
ims/userpic.png ADDED