Update app.py
Browse files
app.py
CHANGED
|
@@ -1,87 +1,26 @@
|
|
| 1 |
-
import openai
|
| 2 |
-
import gradio as gr
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def chatbot(input):
|
| 31 |
-
if input:
|
| 32 |
-
# Add user input to the chat
|
| 33 |
-
messages.append({"role": "user", "content": input})
|
| 34 |
-
|
| 35 |
-
# Search for the information in the Word document
|
| 36 |
-
doc_content = read_word_document("./Info_1.docx") # Specify the path to your Word document
|
| 37 |
-
doc_reply = search_in_doc(doc_content, input)
|
| 38 |
-
|
| 39 |
-
## Get the chatbot response from OpenAI
|
| 40 |
-
#chat = openai.ChatCompletion.create(
|
| 41 |
-
# model="gpt-4", messages=messages
|
| 42 |
-
#)
|
| 43 |
-
#ai_reply = chat.choices[0].message.content
|
| 44 |
-
#messages.append({"role": "assistant", "content": ai_reply})
|
| 45 |
-
|
| 46 |
-
# Combine the response from OpenAI and the document search
|
| 47 |
-
#combined_reply = f"{ai_reply}\n\n{doc_reply}"
|
| 48 |
-
combined_reply = f"{doc_reply}"
|
| 49 |
-
return combined_reply
|
| 50 |
-
|
| 51 |
-
inputs = gr.Textbox(lines=7, label="Chat with AI")
|
| 52 |
-
outputs = gr.Textbox(label="Reply")
|
| 53 |
-
|
| 54 |
-
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The AI Patch & Sparks Chatbot",
|
| 55 |
-
description="Ask anything you want about Patch&Sparks \y(((h",
|
| 56 |
-
theme="compact").launch(share=True)
|
| 57 |
-
|
| 58 |
-
"""
|
| 59 |
-
|
| 60 |
-
import openai
|
| 61 |
-
import gradio as gr
|
| 62 |
-
|
| 63 |
-
openai.api_key = "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"
|
| 64 |
-
|
| 65 |
-
messages = [
|
| 66 |
-
{"role": "system", "content": "You are a chatbot that is very happy and kind. You will search the website https://www.patch-and-sparks.com/en/"},
|
| 67 |
-
]
|
| 68 |
-
|
| 69 |
-
def chatbot(input):
|
| 70 |
-
if input:
|
| 71 |
-
messages.append({"role": "user", "content": input})
|
| 72 |
-
chat = openai.ChatCompletion.create(
|
| 73 |
-
#model="gpt-3.5-turbo", messages=messages
|
| 74 |
-
model="gpt-4o", messages=messages
|
| 75 |
-
)
|
| 76 |
-
reply = chat.choices[0].message.content
|
| 77 |
-
messages.append({"role": "assistant", "content": reply})
|
| 78 |
-
return reply
|
| 79 |
-
|
| 80 |
-
inputs = gr.Textbox(lines=7, label="Chat with AI")
|
| 81 |
-
outputs = gr.Textbox(label="Reply")
|
| 82 |
-
|
| 83 |
-
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The AI Patch & Sparks Chatbot",
|
| 84 |
-
description="Ask anything you want about Patch&Sparks - - - -yeah",
|
| 85 |
-
theme="compact").launch(share=True)
|
| 86 |
-
|
| 87 |
-
"""
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
+
|
| 6 |
+
messages = [
|
| 7 |
+
{"role": "system", "content": "You are a chatbot that is very happy and kind. You will search the website https://www.patch-and-sparks.com/en/"},
|
| 8 |
+
]
|
| 9 |
+
|
| 10 |
+
def chatbot(input):
|
| 11 |
+
if input:
|
| 12 |
+
messages.append({"role": "user", "content": input})
|
| 13 |
+
chat = openai.ChatCompletion.create(
|
| 14 |
+
#model="gpt-3.5-turbo", messages=messages
|
| 15 |
+
model="gpt-4o", messages=messages
|
| 16 |
+
)
|
| 17 |
+
reply = chat.choices[0].message.content
|
| 18 |
+
messages.append({"role": "assistant", "content": reply})
|
| 19 |
+
return reply
|
| 20 |
+
|
| 21 |
+
inputs = gr.Textbox(lines=7, label="Chat with AI")
|
| 22 |
+
outputs = gr.Textbox(label="Reply44")
|
| 23 |
+
|
| 24 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The AI Patch & Sparks Chatbot",
|
| 25 |
+
description="Ask anything you want about Patch&Sparks - - - -yeah",
|
| 26 |
+
theme="compact").launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|