acecalisto3 commited on
Commit
bd92886
·
verified ·
1 Parent(s): 19dc3f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -76,15 +76,15 @@ def run_command(command: str, project_path: str = None) -> str:
76
  process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
77
  output, error = process.communicate()
78
  if error:
79
- return f"Error: {error.decode('utf-8')}"
80
  return.decode("utf-8
81
  except Exception as e:
82
- return f"Error executing command: {stre)}"
83
  _project(project_name: str, project_path: str = DEFAULT_PROJECTPATH):
84
  """Creates a new Hugging Face project."""
85
  global repo
86
  try os.path.exists(project_path):
87
- return f"Error: Directory '{project_path}' already exists!"
88
  # Create the repository
89
  repo = Repository(local_dir=project_path, clone_from=None)
90
  repo.git_init()
@@ -94,9 +94,9 @@ _project(project_name: str, project_path: str = DEFAULT_PROJECTPATH):
94
  # Stage all changes repo.git_add(pattern="*")
95
  repo.git_commit(commit_message="Initial commit")
96
 
97
- return f"Hugging Face project '{project_name}' created successfully at '{project_"
98
  except Exception as e:
99
- return f"Error creating Hugging Face project: {str(e)}"
100
 
101
  def list(project_path: str = DEFAULT_PROJECT_PATH) -> str:
102
  """Lists files in the project directory."""
@@ -105,7 +105,8 @@ def list(project_path: str = DEFAULT_PROJECT_PATH) -> str:
105
  if not files:
106
  return "Project directory is empty."
107
  return "\n".join(files)
108
- except Exception as e: return f"Error listing project {str()}"
 
109
 
110
  def read_file(filepath: str, project_path: str = DEFAULT_PROPATH) -> str """Reads and returns the content of a file in the project."""
111
  try:
@@ -114,7 +115,7 @@ _path = os.path.join(project_path, file_path)
114
  content = f.read()
115
  return content
116
  except Exception as e:
117
- return f"Error reading file: {str(e)}"
118
  def write_file(file_: str, content str project_path str =PROJECT_PATH:
119
  """Writes content to a file in the project."""
120
  try:
@@ -123,7 +124,7 @@ def write_file(file_: str, content str project_path str =PROJECT_PATH:
123
  f.(
124
  return"Successfully wrote to '{_path}'"
125
  except Exception as e:
126
- return f"Error writing to file: {str(e)}"
127
 
128
  def preview(project_path: str = DEFAULT_PROJECT_PATH):
129
  """Provides a preview of the project, if applicable."""
@@ -141,7 +142,7 @@ def preview(project_path: str = DEFAULT_PROJECT_PATH):
141
  return f """preview project: {str(e)}"""
142
 
143
  def main():
144
- .Blocks() as demo:
145
  gr.Markdown("## IDEvIII: Your Hugging No- App Builder")
146
  --- Model Selection --- with gr.Tab("Model"): --- Model Drop with Categories ---
147
  model_categories = gr.Dropdown(
@@ -188,9 +189,9 @@ def main():
188
  global current_model
189
  load_output = load_model(model_name)
190
  if current_model:
191
- return f"Model '{model_name}' loaded successfully!"
192
  else:
193
- return f"Error loading model '{model_name}'"
194
 
195
  load_button.click(load_selected_model, inputs=model_name, outputs=load_output)
196
 
@@ -198,9 +199,9 @@ def main():
198
  with gr.Tab("Chat
199
  chatbot gr.Chatbot(show_label=False, show_share_button=False_copy_button, likeable)
200
  message = gr.Textbox(Enter your message="Ask me anything!")
201
- purpose = gr.Textbox(label="Purpose", placeholder="What is the of this interaction)
202
- agent_name = gr.(label="Ag=["Generic Agent"], value="Generic Agent", interactive=True)
203
- prompt = gr.Textboxlabel="System Prompt", max_lines=1, interactive=True)
204
  temperature = gr.Slider(label="Temperature", value=TEMPERATURE, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Higher values produce more max_newtokens =Slider(labelMax new tokens", value=MAX_TOKENS, minimum=0, maximum=1048 * 10, step=64, interactive=True, info="The maximum numbers of new tokens")
205
  top_p = gr.Slider(label="Top-p (nucleus sampling)", valueTOP_P, minimum=0, maximum=1 step=0.05, interactive=True, info="Higher values sample more low-probability tokens")
206
  repetition_penalty = gr.Slider(label="Repetition penalty", value=REPETITION_PENALTY minimum=1., maximum=2.0,=0.05, interactive=True, info="Penalize repeated tokens")
@@ -236,25 +237,25 @@ prompt = gr.Textboxlabel="System Prompt", max_lines=1, interactive=True)
236
  repo_name = get_full_repo_name(project_name, token=HfApi().token)
237
  repofFolder.create_repo(repo_name, exist_ok=True)
238
  repo.save_data("README.md", f"# {project_name
239
- return f" '{project_name}' on Hugging Face Hub."
240
  except Exception as e:
241
  return"Error project: {str(e)}
242
  def read_file(file_path):
243
  if not os.path.exists(file_path):
244
- return f"File_path}' does exist."
245
 
246
  try
247
  with open(file, "r") as file: content = file()
248
  return content
249
  as e:
250
- return f"Error reading file '{file_path}': {str(e)}"
251
 
252
  def write_file(file_path, file_content): try
253
  with open(file_ "w") as file:
254
  file.write(_content)
255
- f"Wrote to file '{file_path}' successfully."
256
  except Exception as e:
257
- return f"Error writing to file '{file_path}': {str(e)}"
258
 
259
  def run_command(command):
260
  try:
@@ -263,7 +264,7 @@ prompt = gr.Textboxlabel="System Prompt", max_lines=1, interactive=True)
263
  return result.stdout else:
264
  return f"Command '{command failed with exit code {.}:\n{result.stderr}"
265
  except Exception:
266
- return f"Error running command '{command}': {str(e)}"
267
 
268
  def preview():
269
  # Get the current working directory
@@ -293,7 +294,7 @@ prompt = gr.Textboxlabel="System Prompt", max_lines=1, interactive=True)
293
  else:
294
  return "No main found in the project."
295
  except Exception as:
296
- return f"Error generating preview: {str(e)}" finally:
297
  # Remove the directory
298
  .rmtree(tempdir)
299
 
 
76
  process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
77
  output, error = process.communicate()
78
  if error:
79
+ return f"""Error: {error.decode('utf-8')}"""
80
  return.decode("utf-8
81
  except Exception as e:
82
+ return f"""Error executing command: {stre)}"""
83
  _project(project_name: str, project_path: str = DEFAULT_PROJECTPATH):
84
  """Creates a new Hugging Face project."""
85
  global repo
86
  try os.path.exists(project_path):
87
+ return f"""Error: Directory '{project_path}' already exists!"""
88
  # Create the repository
89
  repo = Repository(local_dir=project_path, clone_from=None)
90
  repo.git_init()
 
94
  # Stage all changes repo.git_add(pattern="*")
95
  repo.git_commit(commit_message="Initial commit")
96
 
97
+ return f"""Hugging Face project '{project_name}' created successfully at '{project_path}'"""
98
  except Exception as e:
99
+ return f"""Error creating Hugging Face project: {str(e)}"""
100
 
101
  def list(project_path: str = DEFAULT_PROJECT_PATH) -> str:
102
  """Lists files in the project directory."""
 
105
  if not files:
106
  return "Project directory is empty."
107
  return "\n".join(files)
108
+ except Exception as e:
109
+ return f"""Error listing project {str()}"""
110
 
111
  def read_file(filepath: str, project_path: str = DEFAULT_PROPATH) -> str """Reads and returns the content of a file in the project."""
112
  try:
 
115
  content = f.read()
116
  return content
117
  except Exception as e:
118
+ return f"""Error reading file: {str(e)}"""
119
  def write_file(file_: str, content str project_path str =PROJECT_PATH:
120
  """Writes content to a file in the project."""
121
  try:
 
124
  f.(
125
  return"Successfully wrote to '{_path}'"
126
  except Exception as e:
127
+ return f"""Error writing to file: {str(e)}"""
128
 
129
  def preview(project_path: str = DEFAULT_PROJECT_PATH):
130
  """Provides a preview of the project, if applicable."""
 
142
  return f """preview project: {str(e)}"""
143
 
144
  def main():
145
+ .Blocks() as demo:
146
  gr.Markdown("## IDEvIII: Your Hugging No- App Builder")
147
  --- Model Selection --- with gr.Tab("Model"): --- Model Drop with Categories ---
148
  model_categories = gr.Dropdown(
 
189
  global current_model
190
  load_output = load_model(model_name)
191
  if current_model:
192
+ return f"""Model '{model_name}' loaded successfully!"""
193
  else:
194
+ return f"""Error loading model '{model_name}'"""
195
 
196
  load_button.click(load_selected_model, inputs=model_name, outputs=load_output)
197
 
 
199
  with gr.Tab("Chat
200
  chatbot gr.Chatbot(show_label=False, show_share_button=False_copy_button, likeable)
201
  message = gr.Textbox(Enter your message="Ask me anything!")
202
+ purpose = gr.Textbox(label="Purpose", placeholder="What is the of this interaction)",
203
+ agent_name = gr.(label="Ag=Generic Agent", value="Generic Agent", interactive=True)
204
+ prompt" = gr.Textboxlabel="System Prompt", max_lines=1, interactive=True)
205
  temperature = gr.Slider(label="Temperature", value=TEMPERATURE, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Higher values produce more max_newtokens =Slider(labelMax new tokens", value=MAX_TOKENS, minimum=0, maximum=1048 * 10, step=64, interactive=True, info="The maximum numbers of new tokens")
206
  top_p = gr.Slider(label="Top-p (nucleus sampling)", valueTOP_P, minimum=0, maximum=1 step=0.05, interactive=True, info="Higher values sample more low-probability tokens")
207
  repetition_penalty = gr.Slider(label="Repetition penalty", value=REPETITION_PENALTY minimum=1., maximum=2.0,=0.05, interactive=True, info="Penalize repeated tokens")
 
237
  repo_name = get_full_repo_name(project_name, token=HfApi().token)
238
  repofFolder.create_repo(repo_name, exist_ok=True)
239
  repo.save_data("README.md", f"# {project_name
240
+ return f"""'{project_name}' on Hugging Face Hub."""
241
  except Exception as e:
242
  return"Error project: {str(e)}
243
  def read_file(file_path):
244
  if not os.path.exists(file_path):
245
+ return f"""{File_path}' does exist."""
246
 
247
  try
248
  with open(file, "r") as file: content = file()
249
  return content
250
  as e:
251
+ return f"""Error reading file '{file_path}': {str(e)}"""
252
 
253
  def write_file(file_path, file_content): try
254
  with open(file_ "w") as file:
255
  file.write(_content)
256
+ f"""Wrote to file '{file_path}' successfully."""
257
  except Exception as e:
258
+ return f"""Error writing to file '{file_path}': {str(e)}"""
259
 
260
  def run_command(command):
261
  try:
 
264
  return result.stdout else:
265
  return f"Command '{command failed with exit code {.}:\n{result.stderr}"
266
  except Exception:
267
+ return f"""Error running command '{command}': {str(e)}"""
268
 
269
  def preview():
270
  # Get the current working directory
 
294
  else:
295
  return "No main found in the project."
296
  except Exception as:
297
+ return f"""Error generating preview: {str(e)}""" finally:
298
  # Remove the directory
299
  .rmtree(tempdir)
300