Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,67 @@
|
|
1 |
-
#
|
2 |
import os
|
3 |
import json
|
4 |
-
import
|
5 |
-
|
6 |
-
import
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
import torch
|
9 |
-
|
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
|
22 |
-
import
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
from
|
27 |
-
import
|
28 |
-
import
|
29 |
-
import
|
30 |
-
|
31 |
-
|
32 |
-
import
|
33 |
-
import
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
import pandas as pd
|
37 |
import seaborn as sns
|
38 |
-
import
|
39 |
from matplotlib.gridspec import GridSpec
|
40 |
-
from
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
from
|
45 |
-
|
46 |
-
|
47 |
-
import
|
48 |
-
import
|
|
|
|
|
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 |
-
|
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__)
|