import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer import torch # Load the tokenizer and model from Hugging Face model_name = "waterdrops0/mistral-nouns500" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16) def generate_text(prompt, max_length=50, temperature=0.7): inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device) outputs = model.generate( inputs, max_length=max_length, temperature=temperature, do_sample=True, top_p=0.95, top_k=60 ) text = tokenizer.decode(outputs[0], skip_special_tokens=True) return text # Update to the new gradio components syntax iface = gr.Interface( fn=generate_text, inputs=[ gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt"), gr.Slider(10, 200, step=10, value=50, label="Max Length"), gr.Slider(0.1, 1.0, step=0.1, value=0.7, label="Temperature") ], outputs=gr.Textbox(label="Generated Text"), title="Mistral 7B Nouns Model", description="Generate text using the fine-tuned Mistral 7B model." ) if __name__ == "__main__": iface.launch()