import gradio as gr from transformers import pipeline models = ["gpt2", "microsoft/phi-2","meta-llama/Llama-2-7b-chat-hf" ] def generate_text(prompt, model, max_length, temperature): pipe = pipeline("text-generation", model=model,trust_remote_code = True) try: generated_text = pipe(prompt, max_length=max_length, temperature=temperature)[0]["generated_text"] return generated_text except Exception as e: return f"An error occurred: {str(e)}" gr.Interface( generate_text, [ gr.Textbox(label="Enter your Prompt"), gr.Dropdown(models, label="choose your Model" ), gr.Slider(minimum=50, maximum=650, step=50), gr.Slider(minimum=0.1, maximum=1, step=0.1), ], outputs="text" ).launch()