Spaces:
Sleeping
Sleeping
File size: 1,067 Bytes
7819eb3 e3a17dd 6d59d74 7819eb3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from huggingface_hub import login
import os
import logging
from datetime import datetime
import json
from typing import List, Dict
import warnings
import spaces
# Filter out warnings
warnings.filterwarnings('ignore')
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Environment variables
HF_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
MODEL_NAME = os.getenv("MODEL_NAME", "google/gemma-2-2b-it") # Fixed model name
# Login to Hugging Face with git credential
if HF_TOKEN:
try:
login(token=HF_TOKEN, add_to_git_credential=True)
logger.info("Successfully logged in to Hugging Face")
except Exception as e:
logger.error(f"Error logging in to Hugging Face: {e}")
# Create data directory for persistence
DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
os.makedirs(DATA_DIR, exist_ok=True)
# History file
HISTORY_FILE = os.path.join(DATA_DIR, "review_history.json")
|