naughtondale commited on
Commit
3fbc487
·
1 Parent(s): f47e828

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- import openai
3
  import gradio as gr
4
  import chroma
5
 
@@ -20,6 +20,12 @@ def create_embeddings(text):
20
  def save_embeddings(embeddings):
21
  database.insert_embeddings(embeddings)
22
 
 
 
 
 
 
 
23
  # Function to create a chatbot
24
  def create_chatbot():
25
  engine = gr.engine.Engine(title="Chatbot")
@@ -41,6 +47,13 @@ def create_chatbot():
41
 
42
  return response["choices"][0]["text"]
43
 
 
 
 
 
 
 
 
44
  # Create a button to start the chatbot
45
  button = gr.Button(label="Start Chatting", description="Click to start chatting", on_click=handle_input)
46
 
@@ -53,4 +66,4 @@ def create_chatbot():
53
  chatbot = create_chatbot()
54
 
55
  # Run the chatbot
56
- chatbot.launch()
 
1
  import os
2
+ import openai
3
  import gradio as gr
4
  import chroma
5
 
 
20
  def save_embeddings(embeddings):
21
  database.insert_embeddings(embeddings)
22
 
23
+ # Function to load the source document
24
+ def load_source_document():
25
+ with open("source.txt", "r") as f:
26
+ text = f.read()
27
+ return text
28
+
29
  # Function to create a chatbot
30
  def create_chatbot():
31
  engine = gr.engine.Engine(title="Chatbot")
 
47
 
48
  return response["choices"][0]["text"]
49
 
50
+ # Load the source document
51
+ text = load_source_document()
52
+
53
+ # Create embeddings from the source document and save them in the Chroma database
54
+ embeddings = create_embeddings(text)
55
+ save_embeddings(embeddings)
56
+
57
  # Create a button to start the chatbot
58
  button = gr.Button(label="Start Chatting", description="Click to start chatting", on_click=handle_input)
59
 
 
66
  chatbot = create_chatbot()
67
 
68
  # Run the chatbot
69
+ chatbot.launch()