Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,7 @@ def generation_code(
|
|
34 |
language: str,
|
35 |
provider: str
|
36 |
) -> Tuple[str, History, str, List[Dict[str, str]]]:
|
37 |
-
# Initialize
|
38 |
if query is None:
|
39 |
query = ''
|
40 |
if _history is None:
|
@@ -53,7 +53,7 @@ def generation_code(
|
|
53 |
if website_url:
|
54 |
text = extract_website_content(website_url)
|
55 |
if not text.startswith('Error'):
|
56 |
-
query += f"\n\n[Website]\n{text[:8000]}"
|
57 |
|
58 |
# Web search enhancement
|
59 |
final_query = enhance_query_with_search(query, enable_search)
|
@@ -96,19 +96,25 @@ with gr.Blocks(theme=gr.themes.Base(), title="AnyCoder - AI Code Generator") as
|
|
96 |
|
97 |
with gr.Sidebar():
|
98 |
gr.Markdown("## AnyCoder AI")
|
|
|
99 |
# Load project
|
100 |
url_in = gr.Textbox(label="Load HF Space URL", placeholder="https://huggingface.co/spaces/user/project")
|
101 |
load_btn = gr.Button("Import Project")
|
102 |
load_status = gr.Markdown(visible=False)
|
103 |
|
104 |
gr.Markdown("---")
|
|
|
105 |
# Inputs
|
106 |
prompt_in = gr.Textbox(label="Prompt", lines=3)
|
107 |
file_in = gr.File(label="Reference file")
|
108 |
image_in = gr.Image(label="Design image")
|
109 |
url_site = gr.Textbox(label="Website URL")
|
110 |
search_chk = gr.Checkbox(label="Enable Web Search")
|
111 |
-
language_dd = gr.Dropdown(
|
|
|
|
|
|
|
|
|
112 |
model_dd = gr.Dropdown(
|
113 |
choices=[m['name'] for m in AVAILABLE_MODELS],
|
114 |
value=AVAILABLE_MODELS[0]['name'],
|
@@ -133,8 +139,7 @@ with gr.Blocks(theme=gr.themes.Base(), title="AnyCoder - AI Code Generator") as
|
|
133 |
outputs=[load_status, code_out, preview_out, url_in, history_state, chat_out]
|
134 |
)
|
135 |
|
136 |
-
def on_model_change(name):
|
137 |
-
# find id by name
|
138 |
for m in AVAILABLE_MODELS:
|
139 |
if m['name'] == name:
|
140 |
return m['id']
|
@@ -148,15 +153,18 @@ with gr.Blocks(theme=gr.themes.Base(), title="AnyCoder - AI Code Generator") as
|
|
148 |
|
149 |
gen_btn.click(
|
150 |
fn=generation_code,
|
151 |
-
inputs=[
|
152 |
-
|
153 |
-
|
|
|
|
|
154 |
outputs=[code_out, history_state, preview_out, chat_out]
|
155 |
)
|
156 |
|
157 |
-
clr_btn.click(
|
158 |
-
|
|
|
|
|
159 |
|
160 |
if __name__ == '__main__':
|
161 |
demo.queue().launch()
|
162 |
-
```
|
|
|
34 |
language: str,
|
35 |
provider: str
|
36 |
) -> Tuple[str, History, str, List[Dict[str, str]]]:
|
37 |
+
# Initialize inputs
|
38 |
if query is None:
|
39 |
query = ''
|
40 |
if _history is None:
|
|
|
53 |
if website_url:
|
54 |
text = extract_website_content(website_url)
|
55 |
if not text.startswith('Error'):
|
56 |
+
query += f"\n\n[Website content]\n{text[:8000]}"
|
57 |
|
58 |
# Web search enhancement
|
59 |
final_query = enhance_query_with_search(query, enable_search)
|
|
|
96 |
|
97 |
with gr.Sidebar():
|
98 |
gr.Markdown("## AnyCoder AI")
|
99 |
+
|
100 |
# Load project
|
101 |
url_in = gr.Textbox(label="Load HF Space URL", placeholder="https://huggingface.co/spaces/user/project")
|
102 |
load_btn = gr.Button("Import Project")
|
103 |
load_status = gr.Markdown(visible=False)
|
104 |
|
105 |
gr.Markdown("---")
|
106 |
+
|
107 |
# Inputs
|
108 |
prompt_in = gr.Textbox(label="Prompt", lines=3)
|
109 |
file_in = gr.File(label="Reference file")
|
110 |
image_in = gr.Image(label="Design image")
|
111 |
url_site = gr.Textbox(label="Website URL")
|
112 |
search_chk = gr.Checkbox(label="Enable Web Search")
|
113 |
+
language_dd = gr.Dropdown(
|
114 |
+
choices=["html", "python", "transformers.js"],
|
115 |
+
value="html",
|
116 |
+
label="Language"
|
117 |
+
)
|
118 |
model_dd = gr.Dropdown(
|
119 |
choices=[m['name'] for m in AVAILABLE_MODELS],
|
120 |
value=AVAILABLE_MODELS[0]['name'],
|
|
|
139 |
outputs=[load_status, code_out, preview_out, url_in, history_state, chat_out]
|
140 |
)
|
141 |
|
142 |
+
def on_model_change(name: str) -> str:
|
|
|
143 |
for m in AVAILABLE_MODELS:
|
144 |
if m['name'] == name:
|
145 |
return m['id']
|
|
|
153 |
|
154 |
gen_btn.click(
|
155 |
fn=generation_code,
|
156 |
+
inputs=[
|
157 |
+
prompt_in, image_in, file_in, url_site,
|
158 |
+
setting_state, history_state, model_state,
|
159 |
+
search_chk, language_dd, gr.State('auto')
|
160 |
+
],
|
161 |
outputs=[code_out, history_state, preview_out, chat_out]
|
162 |
)
|
163 |
|
164 |
+
clr_btn.click(
|
165 |
+
fn=lambda: ([], [], "", []),
|
166 |
+
outputs=[history_state, chat_out, preview_out, code_out]
|
167 |
+
)
|
168 |
|
169 |
if __name__ == '__main__':
|
170 |
demo.queue().launch()
|
|