Download app.py from Av77/testav: direct link, hf CLI and curl.
- Browser
- Download file 848 Bytes
-
https://huggingface.co/spaces/Av77/testav/resolve/main/app.py
- Command line
-
hf download hf://spaces/Av77/testav/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Av77/testav/resolve/main/app.py
848 Bytes
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import gradio as gr | |
| # Load the model and tokenizer | |
| model_name = "Qwen/Qwen-7B" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| device_map="auto", | |
| trust_remote_code=True | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) | |
| # Define a function to generate text | |
| def generate_text(input_text): | |
| # Tokenize input | |
| inputs = tokenizer(input_text, return_tensors="pt").to("cuda") | |
| # Generate output | |
| outputs = model.generate(**inputs, max_length=50) | |
| # Decode output | |
| return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # Create Gradio interface | |
| interface = gr.Interface( | |
| fn=generate_text, | |
| inputs="text", | |
| outputs="text", | |
| title="Qwen-7B Text Generator" | |
| ) | |
| # Launch the interface | |
| interface.launch() | |