PearlIsa commited on
Commit
98d76bd
1 Parent(s): 8d4809b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -42
app.py CHANGED
@@ -1,54 +1,67 @@
1
- # app.py
2
  import os
3
  import json
4
- import keras
5
- from datasets import load_dataset
6
- import tensorflow as tf
7
- from huggingface_hub import login
 
 
 
 
 
 
 
 
8
  import torch
9
- from transformers import ( AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer)
10
- from sentence_transformers import SentenceTransformer
11
- from typing import List, Dict, Union, Tuple
12
- import faiss
13
- import numpy as np
14
- from datasets import Dataset
15
  import torch.nn.functional as F
16
  from torch.cuda.amp import autocast
17
- import gc
18
- from peft import ( LoraConfig, get_peft_model, prepare_model_for_kbit_training, TaskType, PeftModel)
19
- from tqdm.auto import tqdm
20
  from torch.utils.data import DataLoader
21
- import logging
22
- import wandb
23
- from pathlib import Path
24
- from typing import List, Dict, Union, Optional, Any
25
- import torch.nn as nn
26
- from dataclasses import dataclass, field
27
- import time
28
- import asyncio
29
- import pytest
30
- from unittest.mock import Mock, patch
31
- from sklearn.metrics import classification_report, confusion_matrix
32
- import gradio as gr
33
- import matplotlib.pyplot as plt
34
- from datetime import datetime
35
- import requests
 
 
 
 
 
 
36
  import pandas as pd
37
  import seaborn as sns
38
- import traceback
39
  from matplotlib.gridspec import GridSpec
40
- from datasets import load_dataset, concatenate_datasets
41
- from langchain.vectorstores import FAISS
42
- from langchain.text_splitter import RecursiveCharacterTextSplitter
43
- from langchain.embeddings import HuggingFaceEmbeddings
44
- from langchain.document_loaders import TextLoader
45
- import IPython.display as display
46
- from peft import get_peft_model, LoraConfig, prepare_model_for_kbit_training
47
- import warnings
48
- import re
 
 
49
  from dotenv import load_dotenv
 
 
 
 
50
  warnings.filterwarnings('ignore')
51
 
 
52
  # Ensure Hugging Face login
53
  try:
54
  hf_token = os.getenv("HF_TOKEN")
@@ -58,13 +71,12 @@ try:
58
  except Exception as e:
59
  print("Hugging Face Login failed:", e)
60
 
61
- # CUDA and Memory Configurations
62
- torch.backends.cuda.matmul.allow_tf32 = False
63
- torch.backends.cudnn.allow_tf32 = False
64
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:64,garbage_collection_threshold:0.8,expandable_segments:True'
65
  os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
66
 
67
 
 
68
  # Setup logging
69
  logging.basicConfig(level=logging.INFO)
70
  logger = logging.getLogger(__name__)
 
1
+ # Standard Libraries
2
  import os
3
  import json
4
+ import time
5
+ import asyncio
6
+ import logging
7
+ import gc
8
+ import re
9
+ import traceback
10
+ from pathlib import Path
11
+ from datetime import datetime
12
+ from typing import List, Dict, Union, Tuple, Optional, Any
13
+ from dataclasses import dataclass, field
14
+
15
+ # Machine Learning and Deep Learning Libraries
16
  import torch
17
+ import torch.nn as nn
 
 
 
 
 
18
  import torch.nn.functional as F
19
  from torch.cuda.amp import autocast
 
 
 
20
  from torch.utils.data import DataLoader
21
+ import tensorflow as tf
22
+ import keras
23
+ import numpy as np
24
+
25
+ # Hugging Face and Transformers
26
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer
27
+ from sentence_transformers import SentenceTransformer
28
+ from datasets import load_dataset, Dataset, concatenate_datasets
29
+ from huggingface_hub import login
30
+
31
+ # FAISS and PEFT
32
+ import faiss
33
+ from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training, TaskType, PeftModel
34
+
35
+ # LangChain - updated imports as per recent deprecations
36
+ from langchain_community.vectorstores import FAISS # Updated import
37
+ from langchain_community.embeddings import HuggingFaceEmbeddings # Updated import
38
+ from langchain_community.document_loaders import TextLoader # Updated import
39
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
40
+
41
+ # Data Science and Visualization Libraries
42
  import pandas as pd
43
  import seaborn as sns
44
+ import matplotlib.pyplot as plt
45
  from matplotlib.gridspec import GridSpec
46
+ from sklearn.metrics import classification_report, confusion_matrix
47
+
48
+ # Development and Testing
49
+ import pytest
50
+ from unittest.mock import Mock, patch
51
+
52
+ # External Tools and APIs
53
+ import wandb
54
+ import requests
55
+ import gradio as gr
56
+ import IPython.display as display # Required for IPython display functionality
57
  from dotenv import load_dotenv
58
+ from tqdm.auto import tqdm
59
+
60
+ # Suppress Warnings
61
+ import warnings
62
  warnings.filterwarnings('ignore')
63
 
64
+
65
  # Ensure Hugging Face login
66
  try:
67
  hf_token = os.getenv("HF_TOKEN")
 
71
  except Exception as e:
72
  print("Hugging Face Login failed:", e)
73
 
74
+
 
 
75
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:64,garbage_collection_threshold:0.8,expandable_segments:True'
76
  os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
77
 
78
 
79
+
80
  # Setup logging
81
  logging.basicConfig(level=logging.INFO)
82
  logger = logging.getLogger(__name__)