Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,7 +141,7 @@ def generate_mini_app_ideas(theme):
|
|
| 141 |
|
| 142 |
def generate_app_code(app_name, app_description, model_name, history):
|
| 143 |
"""Generates code for the selected mini-app using the specified GGUF model."""
|
| 144 |
-
prompt = f"Write a Python script for a {app_description} named {app_name} using Gradio and Streamlit:"
|
| 145 |
agent = get_agent(model_name)
|
| 146 |
generated_code = agent.chat(prompt, history)
|
| 147 |
return generated_code
|
|
@@ -156,11 +156,11 @@ def execute_terminal_command(command):
|
|
| 156 |
|
| 157 |
def install_package(package_name):
|
| 158 |
"""Installs a package using pip."""
|
| 159 |
-
output, error = execute_terminal_command(f"pip install {package_name}")
|
| 160 |
if error:
|
| 161 |
-
return f"Error installing package: {error}"
|
| 162 |
else:
|
| 163 |
-
return f"Package `{package_name}` installed successfully."
|
| 164 |
|
| 165 |
def get_project_data():
|
| 166 |
"""Returns the current project data."""
|
|
@@ -179,7 +179,7 @@ def handle_chat(input_text, history):
|
|
| 179 |
|
| 180 |
if input_text.startswith("pip install ") or input_text.startswith("https://pypi.org/project/"):
|
| 181 |
package_name = extract_package_name(input_text)
|
| 182 |
-
add_message("System", f"Installing `{package_name}`...")
|
| 183 |
result = install_package(package_name)
|
| 184 |
add_message("System", result)
|
| 185 |
update_project_data("packages", CURRENT_PROJECT.get("packages", []) + [package_name])
|
|
@@ -192,15 +192,15 @@ def handle_chat(input_text, history):
|
|
| 192 |
elif not MINI_APPS:
|
| 193 |
add_message("System", "Here are some ideas:")
|
| 194 |
for idea in generate_mini_app_ideas(input_text):
|
| 195 |
-
add_message("System", f"- {idea}")
|
| 196 |
add_message("System", "Which one would you like to build?")
|
| 197 |
elif CURRENT_APP["name"] is None:
|
| 198 |
selected_app = input_text
|
| 199 |
app_description = next((app for app in MINI_APPS if selected_app in app), None)
|
| 200 |
if app_description:
|
| 201 |
-
add_message("System", f"Generating code for {app_description}...")
|
| 202 |
code = generate_app_code(selected_app, app_description, "CodeQwen", history) # Use CodeQwen by default
|
| 203 |
-
add_message("System", f"
|
| 204 |
|
| 205 |
|
| 206 |
python\n{code}\n
|
|
|
|
| 141 |
|
| 142 |
def generate_app_code(app_name, app_description, model_name, history):
|
| 143 |
"""Generates code for the selected mini-app using the specified GGUF model."""
|
| 144 |
+
prompt = f"'"Write a Python script for a {app_description} named {app_name} using Gradio and Streamlit:"'"
|
| 145 |
agent = get_agent(model_name)
|
| 146 |
generated_code = agent.chat(prompt, history)
|
| 147 |
return generated_code
|
|
|
|
| 156 |
|
| 157 |
def install_package(package_name):
|
| 158 |
"""Installs a package using pip."""
|
| 159 |
+
output, error = execute_terminal_command(f"'""pip install {package_name}"'")
|
| 160 |
if error:
|
| 161 |
+
return f"'"Error installing package: {error}"'"
|
| 162 |
else:
|
| 163 |
+
return f"'"Package `{package_name}` installed successfully."'"
|
| 164 |
|
| 165 |
def get_project_data():
|
| 166 |
"""Returns the current project data."""
|
|
|
|
| 179 |
|
| 180 |
if input_text.startswith("pip install ") or input_text.startswith("https://pypi.org/project/"):
|
| 181 |
package_name = extract_package_name(input_text)
|
| 182 |
+
add_message("System", f"'"Installing `{package_name}`...")"'"
|
| 183 |
result = install_package(package_name)
|
| 184 |
add_message("System", result)
|
| 185 |
update_project_data("packages", CURRENT_PROJECT.get("packages", []) + [package_name])
|
|
|
|
| 192 |
elif not MINI_APPS:
|
| 193 |
add_message("System", "Here are some ideas:")
|
| 194 |
for idea in generate_mini_app_ideas(input_text):
|
| 195 |
+
add_message("System", f"'"- {idea}"'")
|
| 196 |
add_message("System", "Which one would you like to build?")
|
| 197 |
elif CURRENT_APP["name"] is None:
|
| 198 |
selected_app = input_text
|
| 199 |
app_description = next((app for app in MINI_APPS if selected_app in app), None)
|
| 200 |
if app_description:
|
| 201 |
+
add_message("System", f"'"Generating code for {app_description}..."'")
|
| 202 |
code = generate_app_code(selected_app, app_description, "CodeQwen", history) # Use CodeQwen by default
|
| 203 |
+
add_message("System", f"'"
|
| 204 |
|
| 205 |
|
| 206 |
python\n{code}\n
|