(model_path: str, MAX_TRY: int = 3)
| 127 | return visitor.found_input |
| 128 | |
| 129 | def gradio_launch(model_path: str, MAX_TRY: int = 3): |
| 130 | with gr.Blocks() as demo: |
| 131 | chatbot = gr.Chatbot(height=600, label="OpenCodeInterpreter", avatar_images=["assets/user.pic.jpg", "assets/assistant.pic.jpg"], show_copy_button=True) |
| 132 | with gr.Group(): |
| 133 | with gr.Row(): |
| 134 | msg = gr.Textbox( |
| 135 | container=False, |
| 136 | show_label=False, |
| 137 | label="Message", |
| 138 | placeholder="Type a message...", |
| 139 | scale=7, |
| 140 | autofocus=True |
| 141 | ) |
| 142 | sub = gr.Button( |
| 143 | "Submit", |
| 144 | variant="primary", |
| 145 | scale=1, |
| 146 | min_width=150 |
| 147 | ) |
| 148 | # stop = gr.Button( |
| 149 | # "Stop", |
| 150 | # variant="stop", |
| 151 | # visible=False, |
| 152 | # scale=1, |
| 153 | # min_width=150 |
| 154 | # ) |
| 155 | |
| 156 | with gr.Row(): |
| 157 | # retry = gr.Button("🔄 Retry", variant="secondary") |
| 158 | # undo = gr.Button("↩️ Undo", variant="secondary") |
| 159 | clear = gr.Button("🗑️ Clear", variant="secondary") |
| 160 | |
| 161 | session_state = gr.State([]) |
| 162 | jupyter_state = gr.State(JupyterNotebook()) |
| 163 | dialog_info = gr.State(["", 0]) |
| 164 | demo.load(update_uuid, dialog_info, dialog_info) |
| 165 | |
| 166 | def bot(user_message, history, jupyter_state, dialog_info, interpreter): |
| 167 | logging.info(f"user message: {user_message}") |
| 168 | interpreter.dialog = convert_history(gradio_history=history, interpreter_history=interpreter.dialog) |
| 169 | history.append([user_message, None]) |
| 170 | |
| 171 | interpreter.dialog.append({"role": "user", "content": user_message}) |
| 172 | |
| 173 | # setup |
| 174 | HAS_CODE = False # For now |
| 175 | prompt = interpreter.dialog_to_prompt(dialog=interpreter.dialog) |
| 176 | |
| 177 | _ = interpreter.generate(prompt) |
| 178 | history[-1][1] = "" |
| 179 | generated_text = "" |
| 180 | for character in interpreter.streamer: |
| 181 | history[-1][1] += character |
| 182 | history[-1][1] = history[-1][1].replace("<|EOT|>","") |
| 183 | generated_text += character |
| 184 | yield history, history, jupyter_state, dialog_info |
| 185 | |
| 186 | if is_valid_python_code(history[-1][1].strip()): |
no test coverage detected