Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from rag import generate_chat_answer, conversation
|
| 4 |
import logging
|
| 5 |
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -10,17 +10,7 @@ def clear_chat():
|
|
| 10 |
conversation.clear_history()
|
| 11 |
return "", []
|
| 12 |
|
| 13 |
-
# Define custom CSS
|
| 14 |
custom_css = """
|
| 15 |
-
.gradio-container {
|
| 16 |
-
background: linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
|
| 17 |
-
url('file:///D:/Huawei NTI Ai Tr aining/Projecttt/Background.png');
|
| 18 |
-
background-size: cover;
|
| 19 |
-
background-position: center;
|
| 20 |
-
background-repeat: no-repeat;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
/* Add rounded corners and shadow to the main container */
|
| 24 |
#container {
|
| 25 |
background: white;
|
| 26 |
border-radius: 15px;
|
|
@@ -30,12 +20,8 @@ custom_css = """
|
|
| 30 |
max-width: 800px;
|
| 31 |
margin-left: auto;
|
| 32 |
margin-right: auto;
|
| 33 |
-
|
| 34 |
}
|
| 35 |
|
| 36 |
-
|
| 37 |
-
/* Style the header */
|
| 38 |
-
|
| 39 |
#header {
|
| 40 |
background: #4CAF50;
|
| 41 |
padding: 20px;
|
|
@@ -45,7 +31,6 @@ custom_css = """
|
|
| 45 |
color: white;
|
| 46 |
}
|
| 47 |
|
| 48 |
-
/* Style the buttons */
|
| 49 |
#buttons-section {
|
| 50 |
display: flex;
|
| 51 |
gap: 10px;
|
|
@@ -72,43 +57,37 @@ custom_css = """
|
|
| 72 |
}
|
| 73 |
"""
|
| 74 |
|
| 75 |
-
|
| 76 |
-
with gr.Blocks(css=custom_css) as interface:
|
| 77 |
with gr.Column(elem_id="container"):
|
| 78 |
with gr.Column(elem_id="header"):
|
| 79 |
gr.Markdown("""
|
| 80 |
# 🌿 Health & Nutrition Assistant
|
| 81 |
### Your AI-powered healthcare knowledge companion
|
| 82 |
""")
|
| 83 |
-
|
| 84 |
-
chatbot = gr.Chatbot(label="Chat History", elem_id="chatbot"
|
| 85 |
query = gr.Textbox(
|
| 86 |
label="Ask me anything about health and nutrition",
|
| 87 |
placeholder="Example: What are the best sources of plant-based protein?",
|
| 88 |
lines=3,
|
| 89 |
elem_id="query-input"
|
| 90 |
)
|
| 91 |
-
|
| 92 |
with gr.Row(elem_id="buttons-section"):
|
| 93 |
submit_btn = gr.Button("Send", elem_id="submit-btn")
|
| 94 |
clear_btn = gr.Button("Clear Chat", elem_id="clear-btn")
|
| 95 |
-
|
| 96 |
-
# Connect the buttons to your RAG functions
|
| 97 |
def respond(query, chat_history):
|
| 98 |
if not query.strip():
|
| 99 |
return "Please enter a valid question.", chat_history
|
| 100 |
-
|
| 101 |
answer = generate_chat_answer(query)
|
| 102 |
chat_history.append({"role": "user", "content": query})
|
| 103 |
chat_history.append({"role": "assistant", "content": answer})
|
| 104 |
-
logger.info(f"Updated Chat History:\n{chat_history}")
|
| 105 |
return "", chat_history
|
| 106 |
|
| 107 |
-
# Update the button click
|
| 108 |
-
|
| 109 |
submit_btn.click(fn=respond, inputs=[query, chatbot], outputs=[query, chatbot])
|
| 110 |
clear_btn.click(fn=clear_chat, outputs=[query, chatbot])
|
| 111 |
|
| 112 |
-
# Launch the interface
|
| 113 |
if __name__ == "__main__":
|
| 114 |
-
interface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from rag import generate_chat_answer, conversation
|
| 4 |
import logging
|
| 5 |
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 10 |
conversation.clear_history()
|
| 11 |
return "", []
|
| 12 |
|
|
|
|
| 13 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
#container {
|
| 15 |
background: white;
|
| 16 |
border-radius: 15px;
|
|
|
|
| 20 |
max-width: 800px;
|
| 21 |
margin-left: auto;
|
| 22 |
margin-right: auto;
|
|
|
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
#header {
|
| 26 |
background: #4CAF50;
|
| 27 |
padding: 20px;
|
|
|
|
| 31 |
color: white;
|
| 32 |
}
|
| 33 |
|
|
|
|
| 34 |
#buttons-section {
|
| 35 |
display: flex;
|
| 36 |
gap: 10px;
|
|
|
|
| 57 |
}
|
| 58 |
"""
|
| 59 |
|
| 60 |
+
with gr.Blocks() as interface:
|
|
|
|
| 61 |
with gr.Column(elem_id="container"):
|
| 62 |
with gr.Column(elem_id="header"):
|
| 63 |
gr.Markdown("""
|
| 64 |
# 🌿 Health & Nutrition Assistant
|
| 65 |
### Your AI-powered healthcare knowledge companion
|
| 66 |
""")
|
| 67 |
+
|
| 68 |
+
chatbot = gr.Chatbot(label="Chat History", elem_id="chatbot")
|
| 69 |
query = gr.Textbox(
|
| 70 |
label="Ask me anything about health and nutrition",
|
| 71 |
placeholder="Example: What are the best sources of plant-based protein?",
|
| 72 |
lines=3,
|
| 73 |
elem_id="query-input"
|
| 74 |
)
|
| 75 |
+
|
| 76 |
with gr.Row(elem_id="buttons-section"):
|
| 77 |
submit_btn = gr.Button("Send", elem_id="submit-btn")
|
| 78 |
clear_btn = gr.Button("Clear Chat", elem_id="clear-btn")
|
| 79 |
+
|
|
|
|
| 80 |
def respond(query, chat_history):
|
| 81 |
if not query.strip():
|
| 82 |
return "Please enter a valid question.", chat_history
|
|
|
|
| 83 |
answer = generate_chat_answer(query)
|
| 84 |
chat_history.append({"role": "user", "content": query})
|
| 85 |
chat_history.append({"role": "assistant", "content": answer})
|
| 86 |
+
logger.info(f"Updated Chat History:\n{chat_history}")
|
| 87 |
return "", chat_history
|
| 88 |
|
|
|
|
|
|
|
| 89 |
submit_btn.click(fn=respond, inputs=[query, chatbot], outputs=[query, chatbot])
|
| 90 |
clear_btn.click(fn=clear_chat, outputs=[query, chatbot])
|
| 91 |
|
|
|
|
| 92 |
if __name__ == "__main__":
|
| 93 |
+
interface.launch(css=custom_css)
|