AvocadoMuffin commited on
Commit
3368d9b
Β·
verified Β·
1 Parent(s): d8f4b0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -26
app.py CHANGED
@@ -71,15 +71,16 @@ def push_existing_model(model_name):
71
  output += "βœ… Login successful!\n\n"
72
 
73
  output += "πŸ“‚ Checking for trained model...\n"
74
- # Check if model exists
75
- if not os.path.exists("./model_output"):
76
- return output + "❌ ./model_output directory not found!\nMake sure you've run training first."
 
77
 
78
  # FIXED: Better error handling for model loading
79
  try:
80
- output += "πŸ“‚ Loading trained model from ./model_output...\n"
81
- model = AutoPeftModelForQuestionAnswering.from_pretrained("./model_output")
82
- tokenizer = AutoTokenizer.from_pretrained("./model_output")
83
  output += "βœ… Model loaded successfully!\n\n"
84
  except Exception as e:
85
  return output + f"❌ Failed to load model: {str(e)}\nMake sure the model was trained successfully."
@@ -95,21 +96,6 @@ def push_existing_model(model_name):
95
  except Exception as e:
96
  return output + f"❌ Failed to push model: {str(e)}\nCheck if model name already exists or token has write permissions."
97
 
98
- # Also push training info if it exists
99
- training_info_path = "./model_output/training_info.json"
100
- if os.path.exists(training_info_path):
101
- try:
102
- from huggingface_hub import upload_file
103
- upload_file(
104
- path_or_fileobj=training_info_path,
105
- path_in_repo="training_info.json",
106
- repo_id=model_name,
107
- repo_type="model"
108
- )
109
- output += "πŸ“Š Training info also uploaded!\n"
110
- except Exception as e:
111
- output += f"⚠️ Training info upload failed: {str(e)}\n"
112
-
113
  return output
114
 
115
  except Exception as e:
@@ -131,7 +117,7 @@ with gr.Blocks(title="RoBERTa CUAD Trainer") as demo:
131
  **Instructions:**
132
  1. Enter your desired model name (format: `AvocadoMuffin/model-name`)
133
  2. Click "Start Training"
134
- 3. Wait ~45-75 minutes for training to complete
135
 
136
  **Example model names:**
137
  - `AvocadoMuffin/roberta-cuad-qa`
@@ -151,9 +137,9 @@ with gr.Blocks(title="RoBERTa CUAD Trainer") as demo:
151
  with gr.Column():
152
  gr.Markdown("""
153
  **Training Details:**
154
- - Model: RoBERTa-base + LoRA
155
- - Dataset: CUAD (4000 samples β†’ ~20K after tokenization)
156
- - Time: ~45-75 minutes
157
  - GPU: T4 (free tier)
158
  - Will auto-push to your HF profile
159
  """)
@@ -191,7 +177,7 @@ with gr.Blocks(title="RoBERTa CUAD Trainer") as demo:
191
  with gr.Column():
192
  gr.Markdown("""
193
  **Requirements:**
194
- - Model must be trained and saved in ./model_output/
195
  - roberta_token must be set in Space secrets
196
  - Takes ~30 seconds
197
  """)
 
71
  output += "βœ… Login successful!\n\n"
72
 
73
  output += "πŸ“‚ Checking for trained model...\n"
74
+ # FIXED: Script 2 saves to ./cuad_lora_out, not ./model_output
75
+ model_dir = "./cuad_lora_out"
76
+ if not os.path.exists(model_dir):
77
+ return output + f"❌ {model_dir} directory not found!\nMake sure you've run training first."
78
 
79
  # FIXED: Better error handling for model loading
80
  try:
81
+ output += f"πŸ“‚ Loading trained model from {model_dir}...\n"
82
+ model = AutoPeftModelForQuestionAnswering.from_pretrained(model_dir)
83
+ tokenizer = AutoTokenizer.from_pretrained(model_dir)
84
  output += "βœ… Model loaded successfully!\n\n"
85
  except Exception as e:
86
  return output + f"❌ Failed to load model: {str(e)}\nMake sure the model was trained successfully."
 
96
  except Exception as e:
97
  return output + f"❌ Failed to push model: {str(e)}\nCheck if model name already exists or token has write permissions."
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  return output
100
 
101
  except Exception as e:
 
117
  **Instructions:**
118
  1. Enter your desired model name (format: `AvocadoMuffin/model-name`)
119
  2. Click "Start Training"
120
+ 3. Wait ~25-30 minutes for training to complete
121
 
122
  **Example model names:**
123
  - `AvocadoMuffin/roberta-cuad-qa`
 
137
  with gr.Column():
138
  gr.Markdown("""
139
  **Training Details:**
140
+ - Model: RoBERTa-base-squad2 + LoRA
141
+ - Dataset: CUAD (balanced, ~18K samples)
142
+ - Time: ~25-30 minutes on L4/T4
143
  - GPU: T4 (free tier)
144
  - Will auto-push to your HF profile
145
  """)
 
177
  with gr.Column():
178
  gr.Markdown("""
179
  **Requirements:**
180
+ - Model must be trained and saved in ./cuad_lora_out/
181
  - roberta_token must be set in Space secrets
182
  - Takes ~30 seconds
183
  """)