Spaces:
Runtime error
Runtime error
Commit ·
801028d
1
Parent(s): c032c99
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,21 +12,19 @@ import time
|
|
| 12 |
from fuzzywuzzy import fuzz
|
| 13 |
import pinecone
|
| 14 |
from getpass import getpass
|
|
|
|
| 15 |
|
| 16 |
os.environ["OPENAI_API_KEY"] = "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"
|
| 17 |
-
YOUR_API_KEY = "
|
| 18 |
-
YOUR_ENV = "
|
| 19 |
|
| 20 |
-
index_name = '
|
| 21 |
pinecone.init(
|
| 22 |
api_key=YOUR_API_KEY,
|
| 23 |
environment=YOUR_ENV
|
| 24 |
)
|
| 25 |
|
| 26 |
|
| 27 |
-
faiss_index_folder_path = "/Users/axelwindbrake/Desktop/AI Automation folders/Chatbot Ver 3/Memory/faiss_index"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
model_name = 'text-embedding-ada-002'
|
| 31 |
|
| 32 |
embed = OpenAIEmbeddings(
|
|
@@ -45,7 +43,7 @@ llm = ChatOpenAI(
|
|
| 45 |
openai_api_key=os.environ["OPENAI_API_KEY"],
|
| 46 |
model_name='gpt-4',
|
| 47 |
temperature=0.5 ,
|
| 48 |
-
max_tokens=
|
| 49 |
)
|
| 50 |
|
| 51 |
qa = RetrievalQA.from_chain_type(
|
|
@@ -81,48 +79,27 @@ with gr.Blocks() as demo:
|
|
| 81 |
clear = gr.Button("Clear")
|
| 82 |
|
| 83 |
def respond(message, chat_history):
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
reader = csv.reader(f)
|
| 89 |
-
for row in reader:
|
| 90 |
-
if fuzz.token_set_ratio(row[0], message) > 80: # Adjust the threshold as needed
|
| 91 |
-
bot_message = row[1]
|
| 92 |
-
break
|
| 93 |
-
else:
|
| 94 |
-
# If the question doesn't have an answer in the CSV file, proceed with the existing process
|
| 95 |
-
bot_response = answer_question(message)
|
| 96 |
-
if isinstance(bot_response, dict) and "answer" in bot_response:
|
| 97 |
-
bot_message = bot_response["answer"]
|
| 98 |
-
else:
|
| 99 |
-
bot_message = "Sorry, I couldn't generate a response."
|
| 100 |
else:
|
| 101 |
-
|
| 102 |
-
message = message[2:]
|
| 103 |
-
bot_response = answer_question(message)
|
| 104 |
-
if isinstance(bot_response, dict) and "answer" in bot_response:
|
| 105 |
-
bot_message = bot_response["answer"]
|
| 106 |
-
else:
|
| 107 |
-
bot_message = "Sorry, I couldn't generate a response."
|
| 108 |
|
| 109 |
# Save to CSV file
|
| 110 |
-
with open(
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
chat_history.append((message, bot_message))
|
| 115 |
time.sleep(1)
|
| 116 |
return "", chat_history
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 122 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 123 |
|
| 124 |
with gr.Blocks() as demo:
|
| 125 |
-
instructions = gr.Markdown("## Willkommen
|
| 126 |
chatbot = gr.Chatbot()
|
| 127 |
msg = gr.Textbox()
|
| 128 |
clear = gr.Button("Clear")
|
|
@@ -132,5 +109,5 @@ with gr.Blocks() as demo:
|
|
| 132 |
|
| 133 |
|
| 134 |
if __name__ == "__main__":
|
| 135 |
-
demo.launch(share=
|
| 136 |
|
|
|
|
| 12 |
from fuzzywuzzy import fuzz
|
| 13 |
import pinecone
|
| 14 |
from getpass import getpass
|
| 15 |
+
from huggingface_hub import HfFileSystem
|
| 16 |
|
| 17 |
os.environ["OPENAI_API_KEY"] = "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"
|
| 18 |
+
YOUR_API_KEY = "93ee455f-e30d-4dad-b44f-567687717fb1"
|
| 19 |
+
YOUR_ENV = "us-west4-gcp-free"
|
| 20 |
|
| 21 |
+
index_name = 'kfo-abrechnung'
|
| 22 |
pinecone.init(
|
| 23 |
api_key=YOUR_API_KEY,
|
| 24 |
environment=YOUR_ENV
|
| 25 |
)
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
model_name = 'text-embedding-ada-002'
|
| 29 |
|
| 30 |
embed = OpenAIEmbeddings(
|
|
|
|
| 43 |
openai_api_key=os.environ["OPENAI_API_KEY"],
|
| 44 |
model_name='gpt-4',
|
| 45 |
temperature=0.5 ,
|
| 46 |
+
max_tokens=850
|
| 47 |
)
|
| 48 |
|
| 49 |
qa = RetrievalQA.from_chain_type(
|
|
|
|
| 79 |
clear = gr.Button("Clear")
|
| 80 |
|
| 81 |
def respond(message, chat_history):
|
| 82 |
+
#message = message[2:]
|
| 83 |
+
bot_response = answer_question(message)
|
| 84 |
+
if isinstance(bot_response, dict) and "answer" in bot_response:
|
| 85 |
+
bot_message = bot_response["answer"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
else:
|
| 87 |
+
bot_message = "Sorry, I couldn't generate a response."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# Save to CSV file
|
| 90 |
+
#with open(csv_file, "a", newline='') as f:
|
| 91 |
+
# writer = csv.writer(f)
|
| 92 |
+
# writer.writerow([message, bot_message])
|
| 93 |
|
| 94 |
chat_history.append((message, bot_message))
|
| 95 |
time.sleep(1)
|
| 96 |
return "", chat_history
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 99 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 100 |
|
| 101 |
with gr.Blocks() as demo:
|
| 102 |
+
instructions = gr.Markdown("## Willkommen zum KFO Abrechnungs-Bot\n\n\nBitte stelle deine Frage in der Textbox unten.")
|
| 103 |
chatbot = gr.Chatbot()
|
| 104 |
msg = gr.Textbox()
|
| 105 |
clear = gr.Button("Clear")
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
+
demo.launch(share=False, inbrowser=True)
|
| 113 |
|