Download app.py from khaled123/test2: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/spaces/khaled123/test2/resolve/main/app.py
- Command line
-
hf download hf://spaces/khaled123/test2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/khaled123/test2/resolve/main/app.py
815 Bytes
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # Load the model and tokenizer | |
| model_name = "khaled123/chess" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| # Define the function to generate text | |
| def generate_text(prompt): | |
| inputs = tokenizer(prompt, return_tensors="pt") | |
| outputs = model.generate(inputs["input_ids"], max_length=50) | |
| generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return generated_text | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_text, | |
| inputs="text", | |
| outputs="text", | |
| title="Chess Model based on LLaMA 2", | |
| description="Type a prompt and the model will generate text based on it." | |
| ) | |
| # Launch the interface | |
| iface.launch() |