acecalisto3 commited on
Commit
22e473a
·
verified ·
1 Parent(s): d0380b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -20,7 +20,7 @@ def get_model_pipeline(model_name):
20
  logging.error(f"Error loading model pipeline: {e}")
21
  return None
22
 
23
- # Generate the code
24
  @st.cache_data
25
  def generate_code(task_description, max_length, temperature, num_return_sequences, model_name):
26
  code_pipeline = get_model_pipeline(model_name)
@@ -30,16 +30,22 @@ def generate_code(task_description, max_length, temperature, num_return_sequence
30
  try:
31
  logging.info(f"Generating code with input: {task_description}")
32
  prompt = f"Develop code for the following task: {task_description}"
33
-
34
- outputs = code_pipeline(prompt, max_length=max_length, num_return_sequences=num_return_sequences, temperature=temperature)
 
 
 
 
 
 
35
  codes = [output['generated_text'] for output in outputs]
36
-
37
  logging.info("Code generation completed successfully.")
38
  return codes
39
  except Exception as e:
40
  logging.error(f"Error generating code: {e}")
41
  return [f"Error generating code: {e}"]
42
-
43
  # Function to save code to a file
44
  def save_code(code, file_name):
45
  try:
@@ -113,5 +119,6 @@ def main():
113
  else:
114
  st.error("Please enter a valid file name.")
115
 
 
116
  if __name__ == "__main__":
117
  main()
 
20
  logging.error(f"Error loading model pipeline: {e}")
21
  return None
22
 
23
+ # Function to generate code
24
  @st.cache_data
25
  def generate_code(task_description, max_length, temperature, num_return_sequences, model_name):
26
  code_pipeline = get_model_pipeline(model_name)
 
30
  try:
31
  logging.info(f"Generating code with input: {task_description}")
32
  prompt = f"Develop code for the following task: {task_description}"
33
+
34
+ outputs = code_pipeline(
35
+ prompt,
36
+ max_length=max_length,
37
+ num_return_sequences=num_return_sequences,
38
+ temperature=temperature,
39
+ truncation=True # Added truncation
40
+ )
41
  codes = [output['generated_text'] for output in outputs]
42
+
43
  logging.info("Code generation completed successfully.")
44
  return codes
45
  except Exception as e:
46
  logging.error(f"Error generating code: {e}")
47
  return [f"Error generating code: {e}"]
48
+
49
  # Function to save code to a file
50
  def save_code(code, file_name):
51
  try:
 
119
  else:
120
  st.error("Please enter a valid file name.")
121
 
122
+
123
  if __name__ == "__main__":
124
  main()