Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,22 +159,59 @@ async def fetch_space_file_content(space_url, file_path):
|
|
| 159 |
except Exception as e:
|
| 160 |
return f"Error: {e}"
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
# Create the Gradio interface
|
| 180 |
with gr.Blocks(css=css) as demo:
|
|
@@ -271,6 +308,41 @@ with gr.Blocks(css=css) as demo:
|
|
| 271 |
with gr.Row():
|
| 272 |
gr.HTML("<button onclick='copyCode(\"space-content-output\")'>Copy Code</button>") # Add the "Copy Code" button
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
submit_space_button = gr.Button("Fetch File Content")
|
| 275 |
submit_space_button.click(
|
| 276 |
fn=fetch_space_file_content,
|
|
|
|
| 159 |
except Exception as e:
|
| 160 |
return f"Error: {e}"
|
| 161 |
|
| 162 |
+
# Function to generate updated code based on user inputs
|
| 163 |
+
def generate_updated_code(space_name, interface_language, changes_requested):
|
| 164 |
+
"""Generates updated code based on user inputs."""
|
| 165 |
+
# Language mapping for interface text
|
| 166 |
+
language_texts = {
|
| 167 |
+
"Russian": {
|
| 168 |
+
"greet": "Привет, {}!",
|
| 169 |
+
"title": "Приложение для приветствия",
|
| 170 |
+
"description": "Простое приложение для приветствия пользователей."
|
| 171 |
+
},
|
| 172 |
+
"English": {
|
| 173 |
+
"greet": "Hello, {}!",
|
| 174 |
+
"title": "Greeting App",
|
| 175 |
+
"description": "A simple app to greet users."
|
| 176 |
+
},
|
| 177 |
+
"Chinese": {
|
| 178 |
+
"greet": "你好, {}!",
|
| 179 |
+
"title": "问候应用程序",
|
| 180 |
+
"description": "一个简单的问候用户的应用程序。"
|
| 181 |
+
},
|
| 182 |
+
"Spanish": {
|
| 183 |
+
"greet": "¡Hola, {}!",
|
| 184 |
+
"title": "Aplicación de Saludo",
|
| 185 |
+
"description": "Una aplicación simple para saludar a los usuarios."
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Get text based on selected language
|
| 190 |
+
texts = language_texts.get(interface_language, language_texts["English"])
|
| 191 |
+
|
| 192 |
+
# Generate the updated code
|
| 193 |
+
code = f"""
|
| 194 |
+
import gradio as gr
|
| 195 |
+
|
| 196 |
+
# Space: {space_name}
|
| 197 |
+
def greet(name):
|
| 198 |
+
return "{texts['greet'].format(name)}"
|
| 199 |
+
|
| 200 |
+
# Interface
|
| 201 |
+
iface = gr.Interface(
|
| 202 |
+
fn=greet,
|
| 203 |
+
inputs="text",
|
| 204 |
+
outputs="text",
|
| 205 |
+
title="{texts['title']}",
|
| 206 |
+
description="{texts['description']}"
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# Additional Changes Requested:
|
| 210 |
+
{changes_requested}
|
| 211 |
|
| 212 |
+
iface.launch()
|
| 213 |
+
"""
|
| 214 |
+
return code.strip()
|
| 215 |
|
| 216 |
# Create the Gradio interface
|
| 217 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 308 |
with gr.Row():
|
| 309 |
gr.HTML("<button onclick='copyCode(\"space-content-output\")'>Copy Code</button>") # Add the "Copy Code" button
|
| 310 |
|
| 311 |
+
# Кнопка Re-edit
|
| 312 |
+
re_edit_button = gr.Button("Re-edit")
|
| 313 |
+
|
| 314 |
+
# Модальное окно для Re-edit
|
| 315 |
+
with gr.Blocks(visible=False) as re_edit_modal:
|
| 316 |
+
gr.Markdown("### Re-edit Your Space")
|
| 317 |
+
space_name_input = gr.Textbox(label="Space Name", placeholder="Enter your Space name")
|
| 318 |
+
interface_language_input = gr.Dropdown(
|
| 319 |
+
label="Interface Language",
|
| 320 |
+
choices=["Russian", "English", "Chinese", "Spanish"],
|
| 321 |
+
value="English"
|
| 322 |
+
)
|
| 323 |
+
changes_requested_input = gr.Textbox(
|
| 324 |
+
label="What do you want to change?",
|
| 325 |
+
placeholder="e.g., Add a new feature, change the interface style, etc."
|
| 326 |
+
)
|
| 327 |
+
apply_changes_button = gr.Button("Apply Changes")
|
| 328 |
+
|
| 329 |
+
# Обработчик для кнопки Re-edit
|
| 330 |
+
def toggle_modal():
|
| 331 |
+
return gr.Blocks.update(visible=True)
|
| 332 |
+
|
| 333 |
+
re_edit_button.click(toggle_modal, outputs=re_edit_modal)
|
| 334 |
+
|
| 335 |
+
# Обработчик для кнопки Apply Changes
|
| 336 |
+
def apply_changes(space_name, interface_language, changes_requested):
|
| 337 |
+
updated_code = generate_updated_code(space_name, interface_language, changes_requested)
|
| 338 |
+
return updated_code
|
| 339 |
+
|
| 340 |
+
apply_changes_button.click(
|
| 341 |
+
fn=apply_changes,
|
| 342 |
+
inputs=[space_name_input, interface_language_input, changes_requested_input],
|
| 343 |
+
outputs=space_content_output
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
submit_space_button = gr.Button("Fetch File Content")
|
| 347 |
submit_space_button.click(
|
| 348 |
fn=fetch_space_file_content,
|