Update app.py
Browse files
app.py
CHANGED
@@ -30,10 +30,24 @@ def chat(message, site,history):
|
|
30 |
response = ""
|
31 |
try:
|
32 |
response = chain.run(input=message)
|
33 |
-
|
|
|
34 |
|
35 |
return history, history
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
gr.Markdown("<h3><center>BMW Chat Bot</center></h3>")
|
|
|
30 |
response = ""
|
31 |
try:
|
32 |
response = chain.run(input=message)
|
33 |
+
markdown = generate_markdown(response)
|
34 |
+
history.append((message, markdown))
|
35 |
|
36 |
return history, history
|
37 |
|
38 |
+
def generate_markdown(obj):
|
39 |
+
md_string = ""
|
40 |
+
|
41 |
+
if 'answer' in obj:
|
42 |
+
md_string += f"**Answer:**\n\n{obj['answer']}\n"
|
43 |
+
|
44 |
+
if 'sources' in obj:
|
45 |
+
sources_list = obj['sources'].strip().split('\n')
|
46 |
+
md_string += "**Sources:**\n\n"
|
47 |
+
for i, source in enumerate(sources_list):
|
48 |
+
md_string += f"{i + 1}. {source}\n"
|
49 |
+
|
50 |
+
return md_string
|
51 |
|
52 |
with gr.Blocks() as demo:
|
53 |
gr.Markdown("<h3><center>BMW Chat Bot</center></h3>")
|