awindbrake commited on
Commit
801028d
·
1 Parent(s): c032c99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -38
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 = "7fd42be9-4380-44f0-8f9e-c6f6a9c2f088"
18
- YOUR_ENV = "northamerica-northeast1-gcp"
19
 
20
- index_name = 'knowledgebase'
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=450
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
- # If the message starts with "??", skip the CSV lookup
85
- if not message.startswith("??"):
86
- # Check if the question already has an answer in the CSV file
87
- with open("q&a.csv", "r", newline='') as f:
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
- # If the message starts with "??", remove the "??" and proceed with the existing process
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("q&a.csv", "a", newline='') as f:
111
- writer = csv.writer(f)
112
- writer.writerow([message, bot_message])
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 zur Vertriebs Knowledgebase\n\n\nBitte stelle deine Frage in der Textbox unten. \n\n\nAntworten werden zunächst in den gespeicherten Chatverläufen gesucht - wenn du das nicht möchtest, beginne deine Frage mit '??'.")
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=True, inbrowser=True)
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