HAMMALE commited on
Commit
dd69132
·
verified ·
1 Parent(s): 09b8bf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -8,8 +8,9 @@ from datetime import datetime
8
  import ast
9
  import operator as op
10
  import wikipedia
 
11
  import torch
12
- from transformers import AutoModelForCausalLM, AutoTokenizer
13
 
14
  class Tool:
15
  def __init__(self, name: str, description: str, func):
@@ -170,37 +171,45 @@ TOOLS = [
170
  ),
171
  ]
172
 
173
- MODEL_NAME = "meta-llama/Llama-3.2-3B-Instruct"
174
  model = None
175
  tokenizer = None
176
  model_loaded = False
 
177
 
178
  def download_and_load_model(progress=gr.Progress()):
179
  """Download and load the model."""
180
- global model, tokenizer, model_loaded
181
 
182
  try:
183
  progress(0, desc="Starting model download...")
184
 
185
- progress(0.2, desc="Downloading tokenizer...")
186
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
 
 
 
 
 
 
 
187
 
188
  if tokenizer.pad_token is None:
189
  tokenizer.pad_token = tokenizer.eos_token
190
 
191
- progress(0.4, desc="Downloading model (this may take several minutes)...")
192
- model = AutoModelForCausalLM.from_pretrained(
193
- MODEL_NAME,
194
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
195
  device_map="auto" if torch.cuda.is_available() else None,
196
  low_cpu_mem_usage=True
197
  )
198
 
199
- progress(0.9, desc="Finalizing...")
200
  model_loaded = True
201
 
202
  progress(1.0, desc="Model loaded successfully!")
203
- return f"Model '{MODEL_NAME}' loaded successfully! You can now run queries."
204
 
205
  except Exception as e:
206
  return f"Error loading model: {str(e)}"
@@ -458,7 +467,7 @@ with gr.Blocks(title="LLM Reasoning Modes Comparison") as demo:
458
  gr.Markdown("""
459
  # LLM Reasoning Modes Comparison
460
 
461
- Compare three reasoning approaches using **Llama-3.2-3B-Instruct**:
462
 
463
  - **Think-Only**: Chain-of-Thought reasoning only (no tools)
464
  - **Act-Only**: Tool use only (no explicit reasoning)
@@ -469,7 +478,7 @@ with gr.Blocks(title="LLM Reasoning Modes Comparison") as demo:
469
 
470
  with gr.Row():
471
  download_btn = gr.Button("Download & Load Model", variant="primary", size="lg")
472
- model_status = gr.Textbox(label="Model Status", value="Model not loaded. Click the button to download.", interactive=False)
473
 
474
  with gr.Row():
475
  with gr.Column(scale=3):
 
8
  import ast
9
  import operator as op
10
  import wikipedia
11
+ from huggingface_hub import snapshot_download
12
  import torch
13
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
14
 
15
  class Tool:
16
  def __init__(self, name: str, description: str, func):
 
171
  ),
172
  ]
173
 
174
+ MODEL_NAME = "openai/gpt-oss-20b"
175
  model = None
176
  tokenizer = None
177
  model_loaded = False
178
+ model_path = None
179
 
180
  def download_and_load_model(progress=gr.Progress()):
181
  """Download and load the model."""
182
+ global model, tokenizer, model_loaded, model_path
183
 
184
  try:
185
  progress(0, desc="Starting model download...")
186
 
187
+ progress(0.1, desc="Downloading model files (this will take several minutes)...")
188
+ model_path = snapshot_download(
189
+ repo_id=MODEL_NAME,
190
+ cache_dir="./model_cache",
191
+ resume_download=True
192
+ )
193
+
194
+ progress(0.6, desc="Loading tokenizer...")
195
+ tokenizer = GPT2Tokenizer.from_pretrained(model_path)
196
 
197
  if tokenizer.pad_token is None:
198
  tokenizer.pad_token = tokenizer.eos_token
199
 
200
+ progress(0.7, desc="Loading model into memory...")
201
+ model = GPT2LMHeadModel.from_pretrained(
202
+ model_path,
203
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
204
  device_map="auto" if torch.cuda.is_available() else None,
205
  low_cpu_mem_usage=True
206
  )
207
 
208
+ progress(0.95, desc="Finalizing...")
209
  model_loaded = True
210
 
211
  progress(1.0, desc="Model loaded successfully!")
212
+ return f"Model 'openai/gpt-oss-20b' loaded successfully! Model path: {model_path}"
213
 
214
  except Exception as e:
215
  return f"Error loading model: {str(e)}"
 
467
  gr.Markdown("""
468
  # LLM Reasoning Modes Comparison
469
 
470
+ Compare three reasoning approaches using **openai/gpt-oss-20b**:
471
 
472
  - **Think-Only**: Chain-of-Thought reasoning only (no tools)
473
  - **Act-Only**: Tool use only (no explicit reasoning)
 
478
 
479
  with gr.Row():
480
  download_btn = gr.Button("Download & Load Model", variant="primary", size="lg")
481
+ model_status = gr.Textbox(label="Model Status", value="Model not loaded. Click to download openai/gpt-oss-20b", interactive=False)
482
 
483
  with gr.Row():
484
  with gr.Column(scale=3):