NITs
Browse files- components.py +28 -29
- requirements.txt +1 -2
components.py
CHANGED
|
@@ -3,7 +3,6 @@ from concurrent.futures import ThreadPoolExecutor
|
|
| 3 |
from typing import Dict, List, Union
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
-
import requests
|
| 7 |
|
| 8 |
import ai
|
| 9 |
|
|
@@ -99,23 +98,21 @@ class CodeTask(TaskComponent):
|
|
| 99 |
label="What would you like to do?",
|
| 100 |
interactive=True,
|
| 101 |
)
|
| 102 |
-
|
| 103 |
-
generate_code = gr.Button("Generate code")
|
| 104 |
-
save_code = gr.Button("Save code")
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
| 107 |
-
with gr.Accordion(label="Generated code")
|
| 108 |
raw_prompt_output = gr.Textbox(
|
| 109 |
label="Raw output",
|
| 110 |
lines=5,
|
| 111 |
interactive=True,
|
| 112 |
)
|
| 113 |
-
packages = gr.Textbox(
|
| 114 |
label="The following packages will be installed",
|
| 115 |
interactive=True,
|
| 116 |
)
|
| 117 |
-
function = gr.Textbox(
|
| 118 |
-
label="
|
| 119 |
lines=10,
|
| 120 |
interactive=True,
|
| 121 |
)
|
|
@@ -123,7 +120,7 @@ class CodeTask(TaskComponent):
|
|
| 123 |
|
| 124 |
self.input = gr.Textbox(
|
| 125 |
interactive=True,
|
| 126 |
-
placeholder="Input to the
|
| 127 |
show_label=False,
|
| 128 |
)
|
| 129 |
with gr.Column():
|
|
@@ -136,18 +133,31 @@ class CodeTask(TaskComponent):
|
|
| 136 |
generate_code.click(
|
| 137 |
self.generate_code,
|
| 138 |
inputs=[code_prompt],
|
| 139 |
-
outputs=[
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
)
|
| 146 |
|
| 147 |
return gr_component
|
| 148 |
|
| 149 |
@staticmethod
|
| 150 |
def generate_code(code_prompt: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
try:
|
| 152 |
raw_prompt_output = ai.llm.next(
|
| 153 |
[
|
|
@@ -189,25 +199,14 @@ class CodeTask(TaskComponent):
|
|
| 189 |
)
|
| 190 |
)
|
| 191 |
except Exception as e:
|
| 192 |
-
|
| 193 |
-
"",
|
| 194 |
-
"",
|
| 195 |
-
"",
|
| 196 |
-
gr.HighlightedText.update(
|
| 197 |
-
value=[
|
| 198 |
-
(
|
| 199 |
-
f"The following variables are being used before being defined :: {str(e)}. Please check your tasks.",
|
| 200 |
-
"ERROR",
|
| 201 |
-
)
|
| 202 |
-
],
|
| 203 |
-
visible=True,
|
| 204 |
-
),
|
| 205 |
)
|
| 206 |
return (
|
| 207 |
raw_prompt_output,
|
| 208 |
packages,
|
| 209 |
function,
|
| 210 |
-
|
| 211 |
)
|
| 212 |
|
| 213 |
def execute(self, url: str) -> str:
|
|
|
|
| 3 |
from typing import Dict, List, Union
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
|
| 7 |
import ai
|
| 8 |
|
|
|
|
| 98 |
label="What would you like to do?",
|
| 99 |
interactive=True,
|
| 100 |
)
|
| 101 |
+
generate_code = gr.Button("Generate code")
|
|
|
|
|
|
|
| 102 |
with gr.Row():
|
| 103 |
with gr.Column():
|
| 104 |
+
with gr.Accordion(label="Generated code", open=False):
|
| 105 |
raw_prompt_output = gr.Textbox(
|
| 106 |
label="Raw output",
|
| 107 |
lines=5,
|
| 108 |
interactive=True,
|
| 109 |
)
|
| 110 |
+
self.packages = gr.Textbox(
|
| 111 |
label="The following packages will be installed",
|
| 112 |
interactive=True,
|
| 113 |
)
|
| 114 |
+
self.function = gr.Textbox(
|
| 115 |
+
label="Code to be executed",
|
| 116 |
lines=10,
|
| 117 |
interactive=True,
|
| 118 |
)
|
|
|
|
| 120 |
|
| 121 |
self.input = gr.Textbox(
|
| 122 |
interactive=True,
|
| 123 |
+
placeholder="Input to the code",
|
| 124 |
show_label=False,
|
| 125 |
)
|
| 126 |
with gr.Column():
|
|
|
|
| 133 |
generate_code.click(
|
| 134 |
self.generate_code,
|
| 135 |
inputs=[code_prompt],
|
| 136 |
+
outputs=[
|
| 137 |
+
raw_prompt_output,
|
| 138 |
+
self.packages,
|
| 139 |
+
self.function,
|
| 140 |
+
error_message,
|
| 141 |
+
],
|
| 142 |
)
|
| 143 |
|
| 144 |
return gr_component
|
| 145 |
|
| 146 |
@staticmethod
|
| 147 |
def generate_code(code_prompt: str):
|
| 148 |
+
raw_prompt_output = ""
|
| 149 |
+
packages = ""
|
| 150 |
+
function = ""
|
| 151 |
+
error_message = gr.HighlightedText.update(None, visible=False)
|
| 152 |
+
|
| 153 |
+
if not code_prompt:
|
| 154 |
+
return (
|
| 155 |
+
raw_prompt_output,
|
| 156 |
+
packages,
|
| 157 |
+
function,
|
| 158 |
+
error_message,
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
try:
|
| 162 |
raw_prompt_output = ai.llm.next(
|
| 163 |
[
|
|
|
|
| 199 |
)
|
| 200 |
)
|
| 201 |
except Exception as e:
|
| 202 |
+
error_message = gr.HighlightedText.update(
|
| 203 |
+
value=[(str(e), "ERROR")], visible=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
)
|
| 205 |
return (
|
| 206 |
raw_prompt_output,
|
| 207 |
packages,
|
| 208 |
function,
|
| 209 |
+
error_message,
|
| 210 |
)
|
| 211 |
|
| 212 |
def execute(self, url: str) -> str:
|
requirements.txt
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
gradio
|
| 2 |
openai
|
| 3 |
-
python-dotenv
|
| 4 |
-
requests==2.28.1
|
|
|
|
| 1 |
gradio
|
| 2 |
openai
|
| 3 |
+
python-dotenv
|
|
|