File size: 1,122 Bytes
92d0469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import interpreter
import gradio as gr
import os
import io
import contextlib

# Paste your OpenAI API key below.
interpreter.api_key = os.environ.get('openai_api_key')

interpreter.auto_run = True

def chat_with_interpreter(message, history=[]):
    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

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",
                        examples=["what is 2+2?", "Can you solve for x: 10x -65=0?", "What are top 10 headlines from BBC from last week?"],
                        clear_btn=None,
                        retry_btn=None,
                        undo_btn=None).queue()
demo.launch(debug=True)