import gradio as gr from transformers import pipeline, set_seed generator = pipeline('text-generation', model='google/palm-2-large-uncased', device=0) def generate_text(prompt, length=50, temperature=0.7, seed=42): set_seed(seed) output = generator(prompt, max_length=length, do_sample=True, temperature=temperature) return output[0]['generated_text'] import gradio as gr from transformers import pipeline, set_seed import logging logging.basicConfig(level=logging.INFO) def generate_text(prompt, length=50, temperature=0.7, seed=42): try: set_seed(seed) generator = pipeline('text-generation', model='google/palm-2-large-uncased', device=0) output = generator(prompt, max_length=length, do_sample=True, temperature=temperature) return output[0]['generated_text'] except Exception as e: logging.error(f"Error generating text: {e}") return "Error generating text. Please try again later." inputs = gr.inputs.Textbox(lines=5, label="Prompt") outputs = gr.outputs.Textbox(label="Output Text") temperature_slider = gr.inputs.Slider(minimum=0.1, maximum=1.5, default=0.7, label="Temperature") length_slider = gr.inputs.Slider(minimum=10, maximum=200, default=50, label="Length") seed_input = gr.inputs.Number(default=42, label="Seed") title = "Generative AI" description = "Use PaLM 2 to generate text based on a prompt." examples = [["The quick brown fox", 50, 0.7, 42]] iface = gr.Interface(fn=generate_text, inputs=[inputs, length_slider, temperature_slider, seed_input], outputs=outputs, title=title, description=description, examples=examples) iface.launch(inbrowser=True, share=True)