Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,13 @@ import os
|
|
| 4 |
import io
|
| 5 |
import contextlib
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
interpreter.api_key = os.environ.get('openai_api_key')
|
| 9 |
|
| 10 |
interpreter.auto_run = True
|
| 11 |
|
| 12 |
def chat_with_interpreter(message, history=[]):
|
|
|
|
| 13 |
if message == 'reset':
|
| 14 |
interpreter.reset()
|
| 15 |
# Redirect stdout to capture the streamed output
|
|
@@ -21,11 +22,16 @@ def chat_with_interpreter(message, history=[]):
|
|
| 21 |
# Return this output so Gradio's ChatInterface can display it
|
| 22 |
return output
|
| 23 |
|
|
|
|
|
|
|
| 24 |
demo = gr.ChatInterface(fn=chat_with_interpreter,
|
| 25 |
title="Open-Interpreter Gradio ChatInterface",
|
| 26 |
description="Open Interpreter lets LLMs run code (Python, Javascript, Shell, and more) locally",
|
| 27 |
examples=["what is 2+2?", "Can you solve for x: 10x -65=0?", "What are top 10 headlines from BBC from last week?"],
|
| 28 |
clear_btn=None,
|
| 29 |
retry_btn=None,
|
| 30 |
-
undo_btn=None
|
|
|
|
|
|
|
|
|
|
| 31 |
demo.launch(debug=True)
|
|
|
|
| 4 |
import io
|
| 5 |
import contextlib
|
| 6 |
|
| 7 |
+
# Use environ variables for saving and using OpenAI API key as below or use from a textbox in gradio UI
|
| 8 |
+
# interpreter.api_key = os.environ.get('openai_api_key')
|
| 9 |
|
| 10 |
interpreter.auto_run = True
|
| 11 |
|
| 12 |
def chat_with_interpreter(message, history=[]):
|
| 13 |
+
interpreter.api_key = openai_api_key
|
| 14 |
if message == 'reset':
|
| 15 |
interpreter.reset()
|
| 16 |
# Redirect stdout to capture the streamed output
|
|
|
|
| 22 |
# Return this output so Gradio's ChatInterface can display it
|
| 23 |
return output
|
| 24 |
|
| 25 |
+
openai_api_key = gr.Textbox(label='OpenAI API Key', intercative=True)
|
| 26 |
+
|
| 27 |
demo = gr.ChatInterface(fn=chat_with_interpreter,
|
| 28 |
title="Open-Interpreter Gradio ChatInterface",
|
| 29 |
description="Open Interpreter lets LLMs run code (Python, Javascript, Shell, and more) locally",
|
| 30 |
examples=["what is 2+2?", "Can you solve for x: 10x -65=0?", "What are top 10 headlines from BBC from last week?"],
|
| 31 |
clear_btn=None,
|
| 32 |
retry_btn=None,
|
| 33 |
+
undo_btn=None,
|
| 34 |
+
additional_inputs=[openai_api_key],
|
| 35 |
+
additional_inputs_accordion_name = "OpenAI API Key"
|
| 36 |
+
).queue()
|
| 37 |
demo.launch(debug=True)
|