Spaces:
Runtime error
Runtime error
File size: 1,601 Bytes
92d0469 b388cf7 92d0469 7d89ada b388cf7 92d0469 b388cf7 5509dbc 33279b7 7312f21 b388cf7 2bbab52 5509dbc 2bbab52 b388cf7 7312f21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import interpreter
import gradio as gr
import os
import io
import contextlib
# Use environ variables for saving and using OpenAI API key as below or use from a textbox in gradio UI
# interpreter.api_key = os.environ.get('openai_api_key')
interpreter.auto_run = True
def chat_with_interpreter(message, history, openai_api_key):
interpreter.api_key = openai_api_key
if message == 'reset':
interpreter.reset()
# Redirect stdout to capture the streamed output
new_stdout = io.StringIO()
with contextlib.redirect_stdout(new_stdout):
interpreter.chat(message)
output = new_stdout.getvalue()
# Return this output so Gradio's ChatInterface can display it
return output
openai_api_key = gr.Textbox(label='OpenAI API Key', intercative=True)
additional_inputs = [openai_api_key]
examples=[["what is 2+2?"],
["Can you solve for x: 10x -65=0?"],
["What are top 10 headlines from BBC from last week?"]
],
demo = gr.ChatInterface(fn=chat_with_interpreter,
title="Open-Interpreter Gradio ChatInterface",
description="Open Interpreter lets LLMs run code (Python, Javascript, Shell, and more) locally",
clear_btn=None,
retry_btn=None,
undo_btn=None,
#examples=examples,
additional_inputs=additional_inputs,
additional_inputs_accordion_name = "OpenAI API Key",
).queue()
demo.launch(debug=True)
|