Download app.py from hpyapali/Recovery: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/hpyapali/Recovery/resolve/main/app.py
- Command line
-
hf download hf://spaces/hpyapali/Recovery/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hpyapali/Recovery/resolve/main/app.py
1.19 kB
| import os | |
| import torch | |
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| from peft import PeftModel | |
| # π Hugging Face token (stored in repo secret as HF_TOKEN) | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| # π Model sources | |
| base_model = "mistralai/Mistral-7B-v0.1" | |
| adapter_path = "./mistral-recovery-model" # Your uploaded LoRA adapter files | |
| # π Load tokenizer and model in FP32 (CPU-safe) | |
| tokenizer = AutoTokenizer.from_pretrained(base_model, use_auth_token=HF_TOKEN) | |
| tokenizer.pad_token = tokenizer.eos_token | |
| model = AutoModelForCausalLM.from_pretrained( | |
| base_model, | |
| torch_dtype=torch.float32, | |
| use_auth_token=HF_TOKEN | |
| ) | |
| model = PeftModel.from_pretrained(model, adapter_path, use_auth_token=HF_TOKEN) | |
| # π§ Pipeline | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=150, temperature=0.7) | |
| # π₯οΈ Gradio UI | |
| def generate(prompt): | |
| return pipe(prompt)[0]['generated_text'] | |
| gr.Interface( | |
| fn=generate, | |
| inputs="text", | |
| outputs="text", | |
| title="ποΈ Mistral Recovery Coach (CPU Mode)", | |
| description="Enter your workout summary and get personalized recovery advice." | |
| ).launch() | |