Upload folder using huggingface_hub
Browse files- .DS_Store +0 -0
- README.md +3 -9
- app.py +87 -0
- app2.py +87 -0
- info_1.docx +0 -0
- key_words.py +22 -0
- rake_find.py +20 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Test_Bot
|
| 3 |
+
app_file: app2.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 4.44.1
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import docx # For reading Word documents
|
| 4 |
+
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
messages = [
|
| 8 |
+
{"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/"},
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def read_word_document(file_path):
|
| 13 |
+
"""Read and return all paragraphs from the Word document."""
|
| 14 |
+
doc = docx.Document(file_path)
|
| 15 |
+
paragraphs = []
|
| 16 |
+
for paragraph in doc.paragraphs:
|
| 17 |
+
paragraphs.append(paragraph.text)
|
| 18 |
+
return paragraphs
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def search_in_doc(paragraphs, search_term):
|
| 22 |
+
"""Search for the term in each paragraph of the document and return the matching paragraph."""
|
| 23 |
+
for paragraph in paragraphs:
|
| 24 |
+
if search_term.lower() in paragraph.lower():
|
| 25 |
+
return f"I found this information in the document: '{paragraph}'"
|
| 26 |
+
return "Sorry, I couldn't find that information in the document."
|
| 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 |
+
"""
|
app2.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import docx # For reading Word documents
|
| 4 |
+
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
messages = [
|
| 8 |
+
{"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/"},
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def read_word_document(file_path):
|
| 13 |
+
"""Read and return all paragraphs from the Word document."""
|
| 14 |
+
doc = docx.Document(file_path)
|
| 15 |
+
paragraphs = []
|
| 16 |
+
for paragraph in doc.paragraphs:
|
| 17 |
+
paragraphs.append(paragraph.text)
|
| 18 |
+
return paragraphs
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def search_in_doc(paragraphs, search_term):
|
| 22 |
+
"""Search for the term in each paragraph of the document and return the matching paragraph."""
|
| 23 |
+
for paragraph in paragraphs:
|
| 24 |
+
if search_term.lower() in paragraph.lower():
|
| 25 |
+
return f"I found this information in the document: '{paragraph}'"
|
| 26 |
+
return "Sorry, I couldn't find that information in the document."
|
| 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",
|
| 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 |
+
"""
|
info_1.docx
ADDED
|
Binary file (13.9 kB). View file
|
|
|
key_words.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spacy
|
| 2 |
+
from spacy.lang.en.stop_words import STOP_WORDS
|
| 3 |
+
|
| 4 |
+
# Load spaCy's English language model
|
| 5 |
+
nlp = spacy.load('en_core_web_sm')
|
| 6 |
+
|
| 7 |
+
def extract_keywords(question):
|
| 8 |
+
# Process the question using spaCy NLP pipeline
|
| 9 |
+
doc = nlp(question)
|
| 10 |
+
|
| 11 |
+
# Extract keywords by removing stopwords, punctuation, and selecting nouns/adjectives
|
| 12 |
+
keywords = [token.text for token in doc if token.is_stop == False and token.is_punct == False and token.pos_ in ['NOUN', 'ADJ', 'VERB']]
|
| 13 |
+
|
| 14 |
+
return keywords
|
| 15 |
+
|
| 16 |
+
# Example chatbot question
|
| 17 |
+
question = "What is the weather like in New York City today?"
|
| 18 |
+
|
| 19 |
+
# Extract keywords
|
| 20 |
+
keywords = extract_keywords(question)
|
| 21 |
+
|
| 22 |
+
print("Keywords:", keywords)
|
rake_find.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rake_nltk import Rake
|
| 2 |
+
|
| 3 |
+
import nltk
|
| 4 |
+
nltk.download('punkt_tab')
|
| 5 |
+
|
| 6 |
+
def extract_keywords_rake(question):
|
| 7 |
+
r = Rake()
|
| 8 |
+
# Extract keywords
|
| 9 |
+
r.extract_keywords_from_text(question)
|
| 10 |
+
keywords = r.get_ranked_phrases()
|
| 11 |
+
|
| 12 |
+
return keywords
|
| 13 |
+
|
| 14 |
+
# Example chatbot question
|
| 15 |
+
question = "What is the weather like in New York City today?"
|
| 16 |
+
|
| 17 |
+
# Extract keywords using Rake
|
| 18 |
+
keywords_rake = extract_keywords_rake(question)
|
| 19 |
+
|
| 20 |
+
print("Keywords:", keywords_rake)
|