Download app.py from Simonsbs/SimonGPT: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/Simonsbs/SimonGPT/resolve/main/app.py
- Command line
-
hf download hf://spaces/Simonsbs/SimonGPT/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Simonsbs/SimonGPT/resolve/main/app.py
718 Bytes
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| # Load the tokenizer and model | |
| model_name = "HuggingFaceTB/SmolLM2-360M-Instruct" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| # Create a text-generation pipeline | |
| generator = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| # Define the response function | |
| def respond(prompt): | |
| response = generator(prompt, max_length=512, do_sample=True, temperature=0.7) | |
| return response[0]["generated_text"] | |
| # Create the Gradio interface | |
| iface = gr.Interface(fn=respond, inputs="text", outputs="text", title="SimonGPT") | |
| # Launch the app | |
| iface.launch() | |