Update app.py
Browse files
app.py
CHANGED
@@ -14,88 +14,20 @@ from chat_processing import (
|
|
14 |
get_gradio_language, send_to_sandbox
|
15 |
)
|
16 |
from file_processing import create_multimodal_message
|
17 |
-
from web_extraction import enhance_query_with_search
|
18 |
from ux_components import create_top_demo_cards
|
19 |
|
20 |
# --- Gradio App UI ---
|
21 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
font
|
29 |
-
|
30 |
-
|
31 |
-
}
|
32 |
-
|
33 |
-
/* Main Title */
|
34 |
-
h1 {
|
35 |
-
color: #0d6efd; /* A more vibrant blue */
|
36 |
-
font-weight: 700;
|
37 |
-
letter-spacing: -1.5px;
|
38 |
-
text-align: center;
|
39 |
-
padding: 1rem 0;
|
40 |
-
}
|
41 |
-
|
42 |
-
/* Column Headers */
|
43 |
-
.col-header {
|
44 |
-
color: #495057;
|
45 |
-
font-weight: 600;
|
46 |
-
text-transform: uppercase;
|
47 |
-
font-size: 0.85rem;
|
48 |
-
letter-spacing: 0.75px;
|
49 |
-
border-bottom: 2px solid #e9ecef;
|
50 |
-
padding-bottom: 10px;
|
51 |
-
margin-bottom: 20px;
|
52 |
-
text-align: left;
|
53 |
-
}
|
54 |
-
|
55 |
-
/* Consistent Label Styling */
|
56 |
-
.gradio-container .label {
|
57 |
-
font-weight: 500;
|
58 |
-
color: #343a40;
|
59 |
-
}
|
60 |
-
|
61 |
-
/* Custom Button Styling */
|
62 |
-
.gradio-container .gr-button {
|
63 |
-
border-radius: 8px !important;
|
64 |
-
font-size: 1rem !important;
|
65 |
-
font-weight: 500;
|
66 |
-
transition: all 0.2s ease-in-out;
|
67 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
68 |
-
}
|
69 |
-
.gradio-container .gr-button-primary {
|
70 |
-
background: linear-gradient(45deg, #0d6efd, #0dcaf0) !important;
|
71 |
-
color: white !important;
|
72 |
-
border: none !important;
|
73 |
-
}
|
74 |
-
.gradio-container .gr-button-primary:hover {
|
75 |
-
transform: translateY(-2px);
|
76 |
-
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
77 |
-
}
|
78 |
-
|
79 |
-
/* Input Textbox Styling */
|
80 |
-
.gradio-container textarea {
|
81 |
-
border-radius: 8px !important;
|
82 |
-
border: 1px solid #ced4da !important;
|
83 |
-
}
|
84 |
-
.gradio-container textarea:focus {
|
85 |
-
border-color: #80bdff !important;
|
86 |
-
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
|
87 |
-
}
|
88 |
-
|
89 |
-
/* Tabs Styling */
|
90 |
-
.gradio-container .tabs > .tab-nav > button {
|
91 |
-
font-weight: 600;
|
92 |
-
color: #6c757d;
|
93 |
-
}
|
94 |
-
.gradio-container .tabs > .tab-nav > button.selected {
|
95 |
-
color: #0d6efd;
|
96 |
-
border-bottom: 3px solid #0d6efd;
|
97 |
-
}
|
98 |
-
"""
|
99 |
|
100 |
def demo_card_click(evt: gr.EventData):
|
101 |
"""Handles clicks on the demo cards to populate the input textbox."""
|
@@ -130,19 +62,29 @@ def demo_card_click(evt: gr.EventData):
|
|
130 |
|
131 |
with gr.Blocks(
|
132 |
theme=gr.themes.Base(
|
133 |
-
primary_hue=
|
134 |
-
secondary_hue=
|
135 |
-
neutral_hue=
|
136 |
font=gr.themes.GoogleFont("Inter"),
|
137 |
font_mono=gr.themes.GoogleFont("JetBrains Mono"),
|
138 |
-
text_size=gr.themes.sizes.
|
139 |
-
spacing_size=gr.themes.sizes.
|
140 |
-
radius_size=gr.themes.sizes.
|
141 |
),
|
142 |
title="AnyCoder - AI Code Generator",
|
143 |
-
css="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
) as demo:
|
145 |
-
gr.HTML("<h1 align='center'>
|
146 |
history = gr.State([])
|
147 |
setting = gr.State({
|
148 |
"system": HTML_SYSTEM_PROMPT,
|
@@ -183,7 +125,7 @@ with gr.Blocks(
|
|
183 |
visible=False # Hidden by default; shown only for ERNIE-VL or GLM-VL
|
184 |
)
|
185 |
with gr.Row(equal_height=True): #Keep buttons vertically aligned
|
186 |
-
btn = gr.Button("Generate", variant="primary", size="lg", scale=2, interactive=False)
|
187 |
clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1)
|
188 |
|
189 |
gr.Markdown("---",)
|
@@ -211,7 +153,7 @@ with gr.Blocks(
|
|
211 |
label="System Prompt",
|
212 |
lines=5
|
213 |
)
|
214 |
-
save_prompt_btn = gr.Button("Save Prompt", variant="secondary", size="sm", min_width=100)
|
215 |
|
216 |
|
217 |
with gr.Column(scale=3):
|
@@ -222,7 +164,7 @@ with gr.Blocks(
|
|
222 |
language="html",
|
223 |
lines=28,
|
224 |
interactive=False,
|
225 |
-
label="Generated Code"
|
226 |
)
|
227 |
with gr.Tab("Preview"):
|
228 |
sandbox = gr.HTML(label="Live Preview")
|
|
|
14 |
get_gradio_language, send_to_sandbox
|
15 |
)
|
16 |
from file_processing import create_multimodal_message
|
17 |
+
from web_extraction import enhance_query_with_search, perform_web_search
|
18 |
from ux_components import create_top_demo_cards
|
19 |
|
20 |
# --- Gradio App UI ---
|
21 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
22 |
|
23 |
+
# Update the Gradio theme to use modern styling
|
24 |
+
theme = gr.themes.Base(
|
25 |
+
primary_hue=gr.themes.colors.blue,
|
26 |
+
secondary_hue=gr.themes.colors.blue, # Keeping it consistent
|
27 |
+
neutral_hue=gr.themes.colors.neutral,
|
28 |
+
font=gr.themes.GoogleFont("Inter"),
|
29 |
+
font_mono=gr.themes.GoogleFont("JetBrains Mono"),
|
30 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
def demo_card_click(evt: gr.EventData):
|
33 |
"""Handles clicks on the demo cards to populate the input textbox."""
|
|
|
62 |
|
63 |
with gr.Blocks(
|
64 |
theme=gr.themes.Base(
|
65 |
+
primary_hue=gr.themes.colors.blue,
|
66 |
+
secondary_hue=gr.themes.colors.blue,
|
67 |
+
neutral_hue=gr.themes.colors.neutral,
|
68 |
font=gr.themes.GoogleFont("Inter"),
|
69 |
font_mono=gr.themes.GoogleFont("JetBrains Mono"),
|
70 |
+
text_size=gr.themes.sizes.text_lg,
|
71 |
+
spacing_size=gr.themes.sizes.spacing_lg,
|
72 |
+
radius_size=gr.themes.sizes.radius_lg,
|
73 |
),
|
74 |
title="AnyCoder - AI Code Generator",
|
75 |
+
css="""
|
76 |
+
.col-header { text-transform: uppercase; font-size: 0.9em; letter-spacing: 0.05em; color: #555; border-bottom: 1px solid #eee; padding-bottom: 0.5em; margin-bottom: 1em; }
|
77 |
+
.col-header + div { margin-top: 0; } /* Remove extra spacing */
|
78 |
+
.gradio-container .gr-button-primary { background: linear-gradient(to right, #42a5f5, #4791db); color: white; } /* Blue gradient */
|
79 |
+
.gradio-container .gr-button-secondary { background-color: #e3f2fd; color: #1e88e5; } /* Lighter blue */
|
80 |
+
.gradio-container .gr-button-small { font-size: 0.875rem; padding: 0.5rem 1rem; } /* Smaller buttons*/
|
81 |
+
.gradio-container .gr-textbox, .gradio-container .gr-dropdown { border-radius: 6px; }
|
82 |
+
.gradio-container .tabs { border-bottom: 2px solid #e0f2f7; } /* Tabs container line */
|
83 |
+
.gradio-container .tabitem { padding: 1rem; } /* Tab content padding*/
|
84 |
+
.gradio-container .gr-code { border-radius: 6px; background-color: #f5f5f5; } /* Code background */
|
85 |
+
"""
|
86 |
) as demo:
|
87 |
+
gr.HTML("<h1 align='center'>Shasha - AI Code Generator</h1>")
|
88 |
history = gr.State([])
|
89 |
setting = gr.State({
|
90 |
"system": HTML_SYSTEM_PROMPT,
|
|
|
125 |
visible=False # Hidden by default; shown only for ERNIE-VL or GLM-VL
|
126 |
)
|
127 |
with gr.Row(equal_height=True): #Keep buttons vertically aligned
|
128 |
+
btn = gr.Button("Generate", variant="primary", size="lg", scale=2, interactive=False,)
|
129 |
clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1)
|
130 |
|
131 |
gr.Markdown("---",)
|
|
|
153 |
label="System Prompt",
|
154 |
lines=5
|
155 |
)
|
156 |
+
save_prompt_btn = gr.Button("Save Prompt", variant="secondary", size="sm", min_width=100, elem_classes="gr-button-small")
|
157 |
|
158 |
|
159 |
with gr.Column(scale=3):
|
|
|
164 |
language="html",
|
165 |
lines=28,
|
166 |
interactive=False,
|
167 |
+
label="Generated Code"
|
168 |
)
|
169 |
with gr.Tab("Preview"):
|
170 |
sandbox = gr.HTML(label="Live Preview")
|