Update app2.py
Browse files
app2.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
-
import docx # For reading Word documents
|
| 5 |
|
| 6 |
-
openai.api_key = "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"
|
| 7 |
|
| 8 |
-
messages = [
|
| 9 |
-
{"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/"},
|
| 10 |
-
]
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def read_word_document(file_path):
|
| 14 |
-
|
| 15 |
doc = docx.Document(file_path)
|
| 16 |
paragraphs = []
|
| 17 |
for paragraph in doc.paragraphs:
|
|
@@ -20,7 +23,8 @@ def read_word_document(file_path):
|
|
| 20 |
|
| 21 |
|
| 22 |
def search_in_doc(paragraphs, search_term):
|
| 23 |
-
|
|
|
|
| 24 |
for paragraph in paragraphs:
|
| 25 |
if search_term.lower() in paragraph.lower():
|
| 26 |
return f"I found this information in the document: '{paragraph}'"
|
|
@@ -49,6 +53,7 @@ def chatbot(input):
|
|
| 49 |
combined_reply = f"{doc_reply}"
|
| 50 |
return combined_reply
|
| 51 |
|
|
|
|
| 52 |
inputs = gr.Textbox(lines=7, label="Chat with AI")
|
| 53 |
outputs = gr.Textbox(label="Reply")
|
| 54 |
|
|
@@ -56,10 +61,12 @@ gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The AI Patch & S
|
|
| 56 |
description="Ask anything you want about Patch&Sparks",
|
| 57 |
theme="compact").launch(share=True)
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
import openai
|
| 62 |
-
import gradio as gr
|
| 63 |
|
| 64 |
openai.api_key = "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"
|
| 65 |
|
|
@@ -85,4 +92,3 @@ gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The AI Patch & S
|
|
| 85 |
description="Ask anything you want about Patch&Sparks - - - -yeah",
|
| 86 |
theme="compact").launch(share=True)
|
| 87 |
|
| 88 |
-
"""
|
|
|
|
| 1 |
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
#import docx # For reading Word documents
|
| 8 |
+
|
| 9 |
+
#openai.api_key = "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"
|
| 10 |
|
| 11 |
+
#messages = [
|
| 12 |
+
# {"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/"},
|
| 13 |
+
#]
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
def read_word_document(file_path):
|
| 17 |
+
#Read and return all paragraphs from the Word document.
|
| 18 |
doc = docx.Document(file_path)
|
| 19 |
paragraphs = []
|
| 20 |
for paragraph in doc.paragraphs:
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def search_in_doc(paragraphs, search_term):
|
| 26 |
+
|
| 27 |
+
#Search for the term in each paragraph of the document and return the matching paragraph.
|
| 28 |
for paragraph in paragraphs:
|
| 29 |
if search_term.lower() in paragraph.lower():
|
| 30 |
return f"I found this information in the document: '{paragraph}'"
|
|
|
|
| 53 |
combined_reply = f"{doc_reply}"
|
| 54 |
return combined_reply
|
| 55 |
|
| 56 |
+
|
| 57 |
inputs = gr.Textbox(lines=7, label="Chat with AI")
|
| 58 |
outputs = gr.Textbox(label="Reply")
|
| 59 |
|
|
|
|
| 61 |
description="Ask anything you want about Patch&Sparks",
|
| 62 |
theme="compact").launch(share=True)
|
| 63 |
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
#import openai
|
| 67 |
+
#import gradio as gr
|
| 68 |
+
"""
|
| 69 |
|
|
|
|
|
|
|
| 70 |
|
| 71 |
openai.api_key = "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"
|
| 72 |
|
|
|
|
| 92 |
description="Ask anything you want about Patch&Sparks - - - -yeah",
|
| 93 |
theme="compact").launch(share=True)
|
| 94 |
|
|
|