add steps and fix css for gradio 5
Browse files- app.py +15 -11
- sandbox/20240310 - CQA - Semantic Routing 1.ipynb +0 -0
- style.css +16 -0
app.py
CHANGED
@@ -142,6 +142,7 @@ async def chat(query,history,audience,sources,reports):
|
|
142 |
}
|
143 |
|
144 |
used_documents = []
|
|
|
145 |
try:
|
146 |
async for event in result:
|
147 |
if "langgraph_node" in event["metadata"]:
|
@@ -155,8 +156,7 @@ async def chat(query,history,audience,sources,reports):
|
|
155 |
docs_html.append(make_html_source(d, i))
|
156 |
|
157 |
used_documents = used_documents + [d.metadata["name"] for d in docs]
|
158 |
-
|
159 |
-
history[-1].content = "Adding source :\n" + "\n".join(np.unique(used_documents))
|
160 |
|
161 |
docs_html = "".join(docs_html)
|
162 |
|
@@ -173,16 +173,20 @@ async def chat(query,history,audience,sources,reports):
|
|
173 |
if start_streaming == False:
|
174 |
start_streaming = True
|
175 |
history.append(ChatMessage(role="assistant", content = ""))
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
history
|
180 |
|
181 |
if event["name"] == "transform_query" and event["event"] =="on_chain_end":
|
182 |
if hasattr(history[-1],"content"):
|
183 |
-
history[-1].content += "Decompose question : \n\n" + "\n".join([q["question"] for q in event["data"]["output"]["remaining_questions"]])
|
|
|
|
|
|
|
184 |
|
185 |
-
|
|
|
186 |
|
187 |
|
188 |
# if event["event"] == "on_chat_model_stream" and event["name"] != "transform_query": # if streaming answer
|
@@ -259,7 +263,7 @@ async def chat(query,history,audience,sources,reports):
|
|
259 |
|
260 |
|
261 |
# history = [tuple(x) for x in history]
|
262 |
-
yield history,docs_html,output_query,output_language,gallery,output_query,output_keywords
|
263 |
|
264 |
except Exception as e:
|
265 |
print(event, "has failed")
|
@@ -328,7 +332,7 @@ async def chat(query,history,audience,sources,reports):
|
|
328 |
# gallery = list(set("|".join(gallery).split("|")))
|
329 |
# gallery = [get_image_from_azure_blob_storage(x) for x in gallery]
|
330 |
|
331 |
-
yield history,docs_html,output_query,output_language,gallery
|
332 |
|
333 |
|
334 |
|
@@ -462,7 +466,7 @@ def vote(data: gr.LikeData):
|
|
462 |
|
463 |
|
464 |
|
465 |
-
with gr.Blocks(title="Climate Q&A",
|
466 |
# user_id_state = gr.State([user_id])
|
467 |
|
468 |
with gr.Tab("ClimateQ&A"):
|
|
|
142 |
}
|
143 |
|
144 |
used_documents = []
|
145 |
+
answer_message_content = ""
|
146 |
try:
|
147 |
async for event in result:
|
148 |
if "langgraph_node" in event["metadata"]:
|
|
|
156 |
docs_html.append(make_html_source(d, i))
|
157 |
|
158 |
used_documents = used_documents + [d.metadata["name"] for d in docs]
|
159 |
+
history[-1].content = "Adding sources :\n\n - " + "\n - ".join(np.unique(used_documents))
|
|
|
160 |
|
161 |
docs_html = "".join(docs_html)
|
162 |
|
|
|
173 |
if start_streaming == False:
|
174 |
start_streaming = True
|
175 |
history.append(ChatMessage(role="assistant", content = ""))
|
176 |
+
answer_message_content += event["data"]["chunk"].content
|
177 |
+
answer_message_content = parse_output_llm_with_sources(answer_message_content)
|
178 |
+
history[-1] = ChatMessage(role="assistant", content = answer_message_content)
|
179 |
+
# history.append(ChatMessage(role="assistant", content = new_message_content))
|
180 |
|
181 |
if event["name"] == "transform_query" and event["event"] =="on_chain_end":
|
182 |
if hasattr(history[-1],"content"):
|
183 |
+
history[-1].content += "Decompose question into sub-questions: \n\n - " + "\n - ".join([q["question"] for q in event["data"]["output"]["remaining_questions"]])
|
184 |
+
|
185 |
+
if event["name"] == "categorize_intent" and event["event"] == "on_chain_start":
|
186 |
+
print("X")
|
187 |
|
188 |
+
yield history,docs_html,output_query,output_language,gallery #,output_query,output_keywords
|
189 |
+
|
190 |
|
191 |
|
192 |
# if event["event"] == "on_chat_model_stream" and event["name"] != "transform_query": # if streaming answer
|
|
|
263 |
|
264 |
|
265 |
# history = [tuple(x) for x in history]
|
266 |
+
# yield history,docs_html,output_query,output_language,gallery,output_query,output_keywords
|
267 |
|
268 |
except Exception as e:
|
269 |
print(event, "has failed")
|
|
|
332 |
# gallery = list(set("|".join(gallery).split("|")))
|
333 |
# gallery = [get_image_from_azure_blob_storage(x) for x in gallery]
|
334 |
|
335 |
+
yield history,docs_html,output_query,output_language,gallery#,output_query,output_keywords
|
336 |
|
337 |
|
338 |
|
|
|
466 |
|
467 |
|
468 |
|
469 |
+
with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=theme,elem_id = "main-component") as demo:
|
470 |
# user_id_state = gr.State([user_id])
|
471 |
|
472 |
with gr.Tab("ClimateQ&A"):
|
sandbox/20240310 - CQA - Semantic Routing 1.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
style.css
CHANGED
@@ -2,6 +2,14 @@
|
|
2 |
/* :root {
|
3 |
--user-image: url('https://ih1.redbubble.net/image.4776899543.6215/st,small,507x507-pad,600x600,f8f8f8.jpg');
|
4 |
} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
.warning-box {
|
7 |
background-color: #fff3cd;
|
@@ -57,6 +65,7 @@ body.dark .tip-box * {
|
|
57 |
|
58 |
.message{
|
59 |
font-size:14px !important;
|
|
|
60 |
}
|
61 |
|
62 |
|
@@ -65,6 +74,10 @@ a {
|
|
65 |
color: inherit;
|
66 |
}
|
67 |
|
|
|
|
|
|
|
|
|
68 |
.card {
|
69 |
background-color: white;
|
70 |
border-radius: 10px;
|
@@ -465,3 +478,6 @@ span.chatbot > p > img{
|
|
465 |
.score-orange{
|
466 |
color:red !important;
|
467 |
}
|
|
|
|
|
|
|
|
2 |
/* :root {
|
3 |
--user-image: url('https://ih1.redbubble.net/image.4776899543.6215/st,small,507x507-pad,600x600,f8f8f8.jpg');
|
4 |
} */
|
5 |
+
.avatar-container.svelte-1x5p6hu:not(.thumbnail-item) img {
|
6 |
+
width: 100%;
|
7 |
+
height: 100%;
|
8 |
+
object-fit: cover;
|
9 |
+
border-radius: 50%;
|
10 |
+
padding: 0px;
|
11 |
+
margin: 0px;
|
12 |
+
}
|
13 |
|
14 |
.warning-box {
|
15 |
background-color: #fff3cd;
|
|
|
65 |
|
66 |
.message{
|
67 |
font-size:14px !important;
|
68 |
+
|
69 |
}
|
70 |
|
71 |
|
|
|
74 |
color: inherit;
|
75 |
}
|
76 |
|
77 |
+
.doc-ref sup{
|
78 |
+
color:#dc2626!important;
|
79 |
+
/* margin-right:1px; */
|
80 |
+
}
|
81 |
.card {
|
82 |
background-color: white;
|
83 |
border-radius: 10px;
|
|
|
478 |
.score-orange{
|
479 |
color:red !important;
|
480 |
}
|
481 |
+
.message-buttons-left.panel.message-buttons.with-avatar {
|
482 |
+
display: none;
|
483 |
+
}
|