Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import numpy as np
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from sentence_transformers import SentenceTransformer
|
| 7 |
-
from gradio.themes import Soft
|
| 8 |
|
| 9 |
# here we define our basic setup. we decided to store all nutrition text files inside a folder called data
|
| 10 |
# this lets us update content later just by dropping new .txt files without changing any code
|
|
@@ -168,46 +167,20 @@ def nutri_chat(message: str, history: list) -> str:
|
|
| 168 |
return build_rag_answer(message)
|
| 169 |
|
| 170 |
|
| 171 |
-
# here we
|
| 172 |
-
#
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
""
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
- what are some healthier drink options than soda?
|
| 186 |
-
- what does a balanced plate usually look like?
|
| 187 |
-
"""
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
chatbot = gr.Chatbot(label="nutribud chat")
|
| 191 |
-
with gr.Row():
|
| 192 |
-
msg = gr.Textbox(
|
| 193 |
-
show_label=False,
|
| 194 |
-
placeholder="type your nutrition question here and press enter...",
|
| 195 |
-
scale=4,
|
| 196 |
-
)
|
| 197 |
-
clear = gr.Button("clear chat", scale=1)
|
| 198 |
-
|
| 199 |
-
# this function connects our rag logic to the visual chat history
|
| 200 |
-
# we append the user message and nutribud’s reply as a pair so they show up as chat bubbles
|
| 201 |
-
def respond(message, history):
|
| 202 |
-
if history is None:
|
| 203 |
-
history = []
|
| 204 |
-
reply = nutri_chat(message, history)
|
| 205 |
-
history = history + [(message, reply)]
|
| 206 |
-
return "", history
|
| 207 |
-
|
| 208 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 209 |
-
clear.click(lambda: ([], ""), None, [chatbot, msg])
|
| 210 |
-
|
| 211 |
|
| 212 |
if __name__ == "__main__":
|
| 213 |
demo.launch()
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 7 |
|
| 8 |
# here we define our basic setup. we decided to store all nutrition text files inside a folder called data
|
| 9 |
# this lets us update content later just by dropping new .txt files without changing any code
|
|
|
|
| 167 |
return build_rag_answer(message)
|
| 168 |
|
| 169 |
|
| 170 |
+
# here we use gradio's chatinterface so the layout feels like a normal chat app
|
| 171 |
+
# our earlier attempts to style themes directly caused version errors, so we keep it simple here
|
| 172 |
+
demo = gr.ChatInterface(
|
| 173 |
+
fn=nutri_chat,
|
| 174 |
+
title="🌿 nutribud — friendly nutrition rag chatbot",
|
| 175 |
+
description=(
|
| 176 |
+
"ask nutribud general questions about healthy eating and it will answer using trusted public health documents.\n"
|
| 177 |
+
"nutribud does not give medical advice or personalized meal plans.\n\n"
|
| 178 |
+
"example questions:\n"
|
| 179 |
+
"• how can i eat more vegetables every day?\n"
|
| 180 |
+
"• what are some healthier drink options than soda?\n"
|
| 181 |
+
"• what does a balanced plate usually look like?"
|
| 182 |
+
),
|
| 183 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
if __name__ == "__main__":
|
| 186 |
demo.launch()
|