|
import gradio as gr |
|
import os |
|
from huggingface_hub import HfApi, login |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
|
|
def process(model_id, dataset): |
|
print("111") |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
model = AutoModelForCausalLM.from_pretrained(model_id) |
|
|
|
print("222") |
|
model_path = model_id |
|
model.save_pretrained(model_path) |
|
login(token=os.environ["HF_TOKEN"]) |
|
api = HfApi() |
|
model_repo_name = "bstraehle/Meta-Llama-3-8B" |
|
|
|
|
|
print("333") |
|
api.create_repo(repo_id=model_repo_name) |
|
|
|
|
|
print("444") |
|
api.upload_folder( |
|
folder_path=model_path, |
|
repo_id=model_repo_name |
|
) |
|
|
|
|
|
print("555") |
|
tokenizer.push_to_hub(model_repo_name) |
|
|
|
return "Done" |
|
|
|
demo = gr.Interface(fn=process, |
|
inputs=[gr.Textbox(label = "Model ID", value = "meta-llama/Meta-Llama-3-8B", lines = 1), |
|
gr.Textbox(label = "Dataset", value = "imdb", lines = 1)], |
|
outputs=[gr.Textbox(label = "Completion")]) |
|
demo.launch() |