Update app.py
Browse files
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
|
| 13 |
|
| 14 |
class Tool:
|
| 15 |
def __init__(self, name: str, description: str, func):
|
|
@@ -170,37 +171,45 @@ TOOLS = [
|
|
| 170 |
),
|
| 171 |
]
|
| 172 |
|
| 173 |
-
MODEL_NAME = "
|
| 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.
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
if tokenizer.pad_token is None:
|
| 189 |
tokenizer.pad_token = tokenizer.eos_token
|
| 190 |
|
| 191 |
-
progress(0.
|
| 192 |
-
model =
|
| 193 |
-
|
| 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.
|
| 200 |
model_loaded = True
|
| 201 |
|
| 202 |
progress(1.0, desc="Model loaded successfully!")
|
| 203 |
-
return f"Model '
|
| 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 **
|
| 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
|
| 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):
|