Spaces:
Sleeping
Sleeping
File size: 1,554 Bytes
2c87f8e 544d134 e4f0059 544d134 44eef32 f40d7c0 2c87f8e b639572 86f7acc cc66454 085df61 8f696d9 085df61 c3cf694 04b6aa6 2c87f8e f59146a 86f7acc 085df61 f59146a 71b9b3b 085df61 2c87f8e 085df61 f59146a 71b9b3b 2c87f8e 44eef32 cc66454 44eef32 30e6ebc 32c5c6f c378e65 0a276c2 c378e65 a758c0d c378e65 a2ca81f 172f5e3 | 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | from huggingface_hub import hf_hub_download, snapshot_download, login
import pandas as pd
import importlib
import importlib.util
import streamlit as st
import sys
import os
from pathlib import Path
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
#login(token=os.environ.get("HF_TOKEN_LLAMA"))
HF_TOKEN = os.environ.get("HF_TOKEN") #get HF_TOKEN
login(token=HF_TOKEN)
USER_NAME = os.getenv("USER_NAME", "").strip().strip('"')
PRIVATE_SPACE_NAME = os.getenv("PRIVATE_SPACE_NAME", "").strip().strip('"')
#Construct the repo ID
REPO_ID = f"{USER_NAME}/{PRIVATE_SPACE_NAME}"
REPO_TYPE = "space"
# sys.path.append(repo_dir)
# Download the entire space, including the fine-tuned model folder
repo_dir = snapshot_download(
repo_id=REPO_ID,
repo_type=REPO_TYPE,
token=HF_TOKEN,
cache_dir="private_space_cache",
force_download=True # Forces redownload
)
# Change the working directory to the downloaded snapshot directory
# This step is very imporptant
os.chdir(repo_dir)
# # Add repo directory to sys.path so Python can find modules inside it
sys.path.append(repo_dir)
# Download specific files (if snapshot_download wasn't used)
app_path = hf_hub_download(
repo_id=REPO_ID,
filename="app.py",
repo_type=REPO_TYPE
)
# Load and execute `app.py`
spec_app = importlib.util.spec_from_file_location("*", app_path)
app_module = importlib.util.module_from_spec(spec_app)
spec_app.loader.exec_module(app_module)
# Now you can use functions from utils_module
result = app_module.main()
|