Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,29 +47,45 @@ rag_chain = (
|
|
47 |
)
|
48 |
import gradio as gr
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
if __name__ == "__main__":
|
75 |
demo.launch()
|
|
|
47 |
)
|
48 |
import gradio as gr
|
49 |
|
50 |
+
# Function to handle prompt and query the RAG chain
|
51 |
+
def handle_prompt(message, history):
|
52 |
+
try:
|
53 |
+
# Stream output
|
54 |
+
out=""
|
55 |
+
for chunk in rag_chain.stream(message):
|
56 |
+
out += chunk
|
57 |
+
yield out
|
58 |
+
except:
|
59 |
+
raise gr.Error("Requests rate limit exceeded")
|
60 |
+
|
61 |
+
|
62 |
+
if __name__=="__main__":
|
63 |
+
|
64 |
+
# Predefined messages and examples
|
65 |
+
description = "AI powered assistant which answers any question related to the [CAMELS simulations](https://www.camel-simulations.org/)."
|
66 |
+
greetingsmessage = "Hi, I'm the CAMELS DocBot, I'm here to assist you with any question related to the CAMELS simulations."
|
67 |
+
example_questions = [
|
68 |
+
"How can I read a halo file?",
|
69 |
+
"Which simulation suites are included in CAMELS?",
|
70 |
+
"Which are the largest volumes in CAMELS simulations?",
|
71 |
+
"Write a complete snippet of code getting the power spectrum of a simulation"
|
72 |
+
]
|
73 |
+
|
74 |
+
# Define customized Gradio chatbot
|
75 |
+
chatbot = gr.Chatbot([{"role":"assistant", "content":greetingsmessage}],
|
76 |
+
type="messages",
|
77 |
+
avatar_images=["ims/userpic.png","ims/camelslogo.jpg"],
|
78 |
+
height="60vh")
|
79 |
+
|
80 |
+
# Define Gradio interface
|
81 |
+
demo = gr.ChatInterface(handle_prompt,
|
82 |
+
type="messages",
|
83 |
+
title="CAMELS DocBot",
|
84 |
+
fill_height=True,
|
85 |
+
examples=example_questions,
|
86 |
+
theme=gr.themes.Soft(),
|
87 |
+
description=description,
|
88 |
+
#cache_examples=False,
|
89 |
+
chatbot=chatbot)
|
90 |
|
|
|
91 |
demo.launch()
|