Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
messages = []
|
| 4 |
|
| 5 |
def chatbot(user_input):
|
| 6 |
global messages
|
| 7 |
messages.append(("user", user_input))
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
messages.append(("assistant", reply))
|
| 10 |
return messages
|
| 11 |
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
-
chatbot_ui = gr.Chatbot()
|
| 14 |
-
msg = gr.Textbox(placeholder="Ask
|
| 15 |
clear = gr.Button("Clear")
|
| 16 |
|
| 17 |
def respond(message, chat_history):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# --- Load your manual file ---
|
| 4 |
+
with open("sierra_manual.txt", "r", encoding="utf-8") as f:
|
| 5 |
+
manual_text = f.read().lower()
|
| 6 |
+
|
| 7 |
messages = []
|
| 8 |
|
| 9 |
def chatbot(user_input):
|
| 10 |
global messages
|
| 11 |
messages.append(("user", user_input))
|
| 12 |
+
|
| 13 |
+
# Search the manual for any words the user typed
|
| 14 |
+
found = []
|
| 15 |
+
for word in user_input.lower().split():
|
| 16 |
+
if word in manual_text:
|
| 17 |
+
start = manual_text.find(word)
|
| 18 |
+
snippet = manual_text[start:start+400] # grab 400 characters around the match
|
| 19 |
+
found.append(snippet)
|
| 20 |
+
|
| 21 |
+
if found:
|
| 22 |
+
reply = "Here’s what I found in the Sierra manual:\n\n" + "\n---\n".join(found[:2])
|
| 23 |
+
else:
|
| 24 |
+
reply = "I couldn’t find that in the Sierra manual."
|
| 25 |
+
|
| 26 |
messages.append(("assistant", reply))
|
| 27 |
return messages
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
+
chatbot_ui = gr.Chatbot(type="messages")
|
| 31 |
+
msg = gr.Textbox(placeholder="Ask about your Sierra…")
|
| 32 |
clear = gr.Button("Clear")
|
| 33 |
|
| 34 |
def respond(message, chat_history):
|