LamiaYT commited on
Commit
f0b3f91
·
1 Parent(s): 943593c
Files changed (2) hide show
  1. app.py +10 -18
  2. requirements.txt +1 -1
app.py CHANGED
@@ -5,18 +5,17 @@ import json
5
  import re
6
  import numexpr
7
  import pandas as pd
8
- import time
9
- import torch
10
  import math
11
  import pdfminer
12
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
13
  from duckduckgo_search import DDGS
14
  from pdfminer.high_level import extract_text
15
  from bs4 import BeautifulSoup
16
  import html2text
17
  from typing import Dict, Any, List, Tuple, Callable
18
  from dotenv import load_dotenv
19
-
 
 
20
  # --- Load Environment Variables ---
21
  load_dotenv()
22
  SERPER_API_KEY = os.getenv("SERPER_API_KEY")
@@ -32,30 +31,23 @@ os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
32
  os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
33
  os.environ["BITSANDBYTES_NOWELCOME"] = "1"
34
 
35
- # --- Load Quantized Model ---
36
- print("Loading quantized model...")
37
- start_time = time.time()
38
 
39
- # Configure 4-bit quantization
40
- quant_config = BitsAndBytesConfig(
41
- load_in_4bit=True,
42
- bnb_4bit_quant_type="nf4",
43
- bnb_4bit_use_double_quant=True,
44
- bnb_4bit_compute_dtype=torch.bfloat16
45
- )
46
 
47
- # Load model and tokenizer
48
  model = AutoModelForCausalLM.from_pretrained(
49
  MODEL_NAME,
50
- device_map="auto",
51
- quantization_config=quant_config,
52
- trust_remote_code=True
53
  )
54
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
55
 
56
  load_time = time.time() - start_time
57
  print(f"Model loaded in {load_time:.2f} seconds")
58
 
 
59
  # --- Tools for GAIA Agent ---
60
  def web_search(query: str) -> str:
61
  """Search the web using DuckDuckGo or Serper API"""
 
5
  import re
6
  import numexpr
7
  import pandas as pd
 
 
8
  import math
9
  import pdfminer
 
10
  from duckduckgo_search import DDGS
11
  from pdfminer.high_level import extract_text
12
  from bs4 import BeautifulSoup
13
  import html2text
14
  from typing import Dict, Any, List, Tuple, Callable
15
  from dotenv import load_dotenv
16
+ from transformers import AutoModelForCausalLM, AutoTokenizer
17
+ import torch
18
+ import time
19
  # --- Load Environment Variables ---
20
  load_dotenv()
21
  SERPER_API_KEY = os.getenv("SERPER_API_KEY")
 
31
  os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
32
  os.environ["BITSANDBYTES_NOWELCOME"] = "1"
33
 
 
 
 
34
 
35
+ MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct"
36
+
37
+ print("Loading model (CPU-compatible)...")
38
+ start_time = time.time()
 
 
 
39
 
 
40
  model = AutoModelForCausalLM.from_pretrained(
41
  MODEL_NAME,
42
+ trust_remote_code=True,
43
+ torch_dtype=torch.float32 # Use float32 for CPU compatibility
 
44
  )
45
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
46
 
47
  load_time = time.time() - start_time
48
  print(f"Model loaded in {load_time:.2f} seconds")
49
 
50
+
51
  # --- Tools for GAIA Agent ---
52
  def web_search(query: str) -> str:
53
  """Search the web using DuckDuckGo or Serper API"""
requirements.txt CHANGED
@@ -17,7 +17,7 @@ regex>=2023.10.3
17
  numexpr
18
  torch
19
  pdfminer.six
20
- transformers==4.39.3
21
  duckduckgo-search>=0.8
22
  beautifulsoup4>=4.12.0
23
  html2text>=2020.1.16
 
17
  numexpr
18
  torch
19
  pdfminer.six
20
+ transformers>=4.0.0
21
  duckduckgo-search>=0.8
22
  beautifulsoup4>=4.12.0
23
  html2text>=2020.1.16