Download app.py from EzioDevio/HG-test-model: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/EzioDevio/HG-test-model/resolve/main/app.py
- Command line
-
hf download hf://EzioDevio/HG-test-model/app.py
-
curl -L -o app.py https://huggingface.co/EzioDevio/HG-test-model/resolve/main/app.py
1.04 kB
| import gradio as gr | |
| from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer | |
| # Load model and tokenizer from Hugging Face model repository | |
| model_path = "EzioDevio/iraqi_dialect_llm" # Use the Hugging Face Hub model path | |
| # Load the model and tokenizer directly from Hugging Face | |
| model = AutoModelForCausalLM.from_pretrained(model_path) | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| # Define the text generation function | |
| def generate_text(input_text): | |
| generated = text_generator(input_text, max_length=50, num_return_sequences=1) | |
| return generated[0]["generated_text"] | |
| # Set up the Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_text, | |
| inputs="text", | |
| outputs="text", | |
| title="Iraqi Dialect Language Model", | |
| description="Generate text in Iraqi Arabic dialect.", | |
| examples=["شلونك اليوم؟", "وين رايح؟", "صباح الخير"] | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| iface.launch() | |