Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,16 +30,25 @@ def ask_ai():
|
|
| 30 |
response = index.query(query, response_mode="compact")
|
| 31 |
display(Markdown(f"Response: <b>{response.response}</b>"))
|
| 32 |
'''
|
| 33 |
-
def ask_ai(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
| 35 |
-
response = index.query(
|
| 36 |
return response.response
|
| 37 |
|
| 38 |
-
#input your api key
|
| 39 |
-
os.environ["OPENAI_API_KEY"] = "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"
|
| 40 |
|
| 41 |
train_with_data("data")
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
iface.launch()
|
|
|
|
| 30 |
response = index.query(query, response_mode="compact")
|
| 31 |
display(Markdown(f"Response: <b>{response.response}</b>"))
|
| 32 |
'''
|
| 33 |
+
def ask_ai(query, api_key):
|
| 34 |
+
# Set default API key if user does not enter a key
|
| 35 |
+
if api_key == "":
|
| 36 |
+
api_key = "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"
|
| 37 |
+
|
| 38 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 39 |
+
|
| 40 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
| 41 |
+
response = index.query(query, response_mode="compact")
|
| 42 |
return response.response
|
| 43 |
|
|
|
|
|
|
|
| 44 |
|
| 45 |
train_with_data("data")
|
| 46 |
|
| 47 |
+
# Create Gradio interface to prompt for API key
|
| 48 |
+
api_key = gr.inputs.Textbox(label="Enter your OpenAI API key (leave blank to use default key):")
|
| 49 |
+
|
| 50 |
+
# Define the interface
|
| 51 |
+
iface = gr.Interface(fn=ask_ai, inputs=["text", api_key], outputs="text" ,title="Jim's Chatbot")
|
| 52 |
+
|
| 53 |
+
# Start the interface
|
| 54 |
iface.launch()
|