acecalisto3 commited on
Commit
417a425
·
verified ·
1 Parent(s): 2cdc6c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -10,6 +10,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
10
  if 'generated_codes' not in st.session_state:
11
  st.session_state.generated_codes = []
12
 
 
13
  @st.cache_resource
14
  def get_model_pipeline(model_name):
15
  try:
@@ -19,6 +20,7 @@ def get_model_pipeline(model_name):
19
  logging.error(f"Error loading model pipeline: {e}")
20
  return None
21
 
 
22
  @st.cache_data
23
  def generate_code(task_description, max_length, temperature, num_return_sequences, model_name):
24
  code_pipeline = get_model_pipeline(model_name)
@@ -38,6 +40,7 @@ def generate_code(task_description, max_length, temperature, num_return_sequence
38
  logging.error(f"Error generating code: {e}")
39
  return [f"Error generating code: {e}"]
40
 
 
41
  def save_code(code, file_name):
42
  try:
43
  with open(file_name, "w") as file:
@@ -47,6 +50,7 @@ def save_code(code, file_name):
47
  logging.error(f"Error saving code: {e}")
48
  return False
49
 
 
50
  def main():
51
  st.set_page_config(page_title="Advanced Code Generator", layout="wide")
52
 
@@ -70,7 +74,7 @@ def main():
70
  st.header("Options")
71
  col1, col2, col3 = st.columns(3)
72
  with col1:
73
- max_length = st.slider("Max Length", min_value=50, max_value=1000, value=250, step=50, help="Maximum length of the generated code.")
74
  with col2:
75
  temperature = st.slider("Temperature", min_value=0.1, max_value=1.0, value=0.7, step=0.1, help="Controls the creativity of the generated code.")
76
  with col3:
@@ -79,6 +83,8 @@ def main():
79
  # Generate Code Button
80
  if st.button("Generate Code"):
81
  if task_description.strip():
 
 
82
  with st.spinner("Generating code..."):
83
  st.session_state.generated_codes = generate_code(task_description, max_length, temperature, num_return_sequences, model_name)
84
  st.header("Generated Code")
 
10
  if 'generated_codes' not in st.session_state:
11
  st.session_state.generated_codes = []
12
 
13
+ # Function to get the model pipeline
14
  @st.cache_resource
15
  def get_model_pipeline(model_name):
16
  try:
 
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)
 
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:
46
  with open(file_name, "w") as file:
 
50
  logging.error(f"Error saving code: {e}")
51
  return False
52
 
53
+ # Main function for Streamlit app
54
  def main():
55
  st.set_page_config(page_title="Advanced Code Generator", layout="wide")
56
 
 
74
  st.header("Options")
75
  col1, col2, col3 = st.columns(3)
76
  with col1:
77
+ max_length = st.slider("Max Length", min_value=50, max_value=2048, value=250, step=50, help="Maximum length of the generated code.")
78
  with col2:
79
  temperature = st.slider("Temperature", min_value=0.1, max_value=1.0, value=0.7, step=0.1, help="Controls the creativity of the generated code.")
80
  with col3:
 
83
  # Generate Code Button
84
  if st.button("Generate Code"):
85
  if task_description.strip():
86
+ # Clear previous generated codes
87
+ st.session_state.generated_codes = []
88
  with st.spinner("Generating code..."):
89
  st.session_state.generated_codes = generate_code(task_description, max_length, temperature, num_return_sequences, model_name)
90
  st.header("Generated Code")