Spaces:
Configuration error
Configuration error
Download app.py from prodnobody/Linkhub: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/prodnobody/Linkhub/resolve/main/app.py
- Command line
-
hf download hf://spaces/prodnobody/Linkhub/app.py
-
curl -L -o app.py https://huggingface.co/spaces/prodnobody/Linkhub/resolve/main/app.py
1.61 kB
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| from pathlib import Path | |
| # ----------------------------------------- | |
| # CONFIG: choose model source | |
| # ----------------------------------------- | |
| USE_LOCAL_MODEL = False | |
| LOCAL_MODEL_PATH = "model" | |
| HF_MODEL = "meta-llama/Llama-3.1-8B-Instruct" # swap to any model | |
| # ----------------------------------------- | |
| # LOAD MODEL | |
| # ----------------------------------------- | |
| def load_model(): | |
| if USE_LOCAL_MODEL: | |
| tokenizer = AutoTokenizer.from_pretrained(LOCAL_MODEL_PATH) | |
| model = AutoModelForCausalLM.from_pretrained(LOCAL_MODEL_PATH) | |
| else: | |
| tokenizer = AutoTokenizer.from_pretrained(HF_MODEL) | |
| model = AutoModelForCausalLM.from_pretrained(HF_MODEL) | |
| pipe = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| max_new_tokens=256, | |
| temperature=0.7 | |
| ) | |
| return pipe | |
| pipe = load_model() | |
| # ----------------------------------------- | |
| # AGENT FUNCTION | |
| # ----------------------------------------- | |
| def agent_chat(message): | |
| result = pipe(message)[0]["generated_text"] | |
| return result | |
| # ----------------------------------------- | |
| # GRADIO UI | |
| # ----------------------------------------- | |
| with gr.Blocks(title="Luke Ponga – HF Agent Demo") as demo: | |
| gr.Markdown("# 🤖 Luke’s Hugging Face Agent Demo") | |
| gr.Markdown("Chat with a model loaded from HF Hub or your local folder.") | |
| inp = gr.Textbox(label="Message") | |
| out = gr.Textbox(label="Response") | |
| gr.Button("Run Agent").click(agent_chat, inp, out) | |
| demo.launch() |