import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM import torch # Load model model_id = "htigenai/finetune_test" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.float16, device_map="auto" ) def generate_text(prompt): inputs = tokenizer(prompt, return_tensors="pt").to(model.device) outputs = model.generate( **inputs, max_new_tokens=100, temperature=0.7, top_p=0.95, do_sample=True ) return tokenizer.decode(outputs[0], skip_special_tokens=True) # Create the interface iface = gr.Interface( fn=generate_text, inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."), outputs=gr.Textbox(), title="Text Generation", description="Generate text using the fine-tuned model" ) iface.launch()