fastx commited on
Commit
2ba8091
·
1 Parent(s): 2ec53c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -6,6 +6,8 @@ import sys
6
  import os
7
  from IPython.display import Markdown, display
8
 
 
 
9
 
10
  def construct_index(directory_path):
11
  # set maximum input size
@@ -29,34 +31,20 @@ def construct_index(directory_path):
29
 
30
  return index
31
 
32
-
33
-
34
-
35
- '''
36
- def ask_ai():
37
- index = GPTSimpleVectorIndex.load_from_disk('index.json')
38
- while True:
39
- query = input("What do you want to ask? ")
40
- response = index.query(query, response_mode="compact")
41
- display(Markdown(f"Response: <b>{response.response}</b>"))
42
- '''
43
- # Define the ask_ai() function
44
- def ask_ai(question,api):
45
- if api == "":
46
- api = "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"
47
- os.environ["OPENAI_API_KEY"] = api
48
  index = GPTSimpleVectorIndex.load_from_disk('index.json')
49
  response = index.query(question, response_mode="compact")
50
  return response.response
51
 
52
-
53
  construct_index("data")
54
 
55
  # Create Gradio interface to prompt for API key
56
- api_key = gr.inputs.Textbox(label="Enter your OpenAI API key:")
57
 
58
  # Define the interface
59
- iface = gr.Interface(fn=ask_ai, inputs=["text", api_key], outputs="text" ,title="Jim's Chatbot")
60
 
61
  # Start the interface
62
- iface.launch()
 
6
  import os
7
  from IPython.display import Markdown, display
8
 
9
+ # Define API key globally
10
+ api_key = "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"
11
 
12
  def construct_index(directory_path):
13
  # set maximum input size
 
31
 
32
  return index
33
 
34
+ def ask_ai(question, api_key):
35
+ # Use global API key variable
36
+ os.environ["OPENAI_API_KEY"] = api_key
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  index = GPTSimpleVectorIndex.load_from_disk('index.json')
38
  response = index.query(question, response_mode="compact")
39
  return response.response
40
 
 
41
  construct_index("data")
42
 
43
  # Create Gradio interface to prompt for API key
44
+ api_key_input = gr.inputs.Textbox(label="Enter your OpenAI API key:")
45
 
46
  # Define the interface
47
+ iface = gr.Interface(fn=ask_ai, inputs=["text", api_key_input], outputs="text" ,title="Jim's Chatbot")
48
 
49
  # Start the interface
50
+ iface.launch()