import gradio as gr from transformers import pipeline models = { "MagicPrompt": "pszemraj/distilgpt2-magicprompt-SD", "DistilGPT2 SD": "FredZhang7/distilgpt2-stable-diffusion", "Llama-SmolTalk-3.2-1B": "prithivMLmods/Llama-SmolTalk-3.2-1B-Instruct" } pipelines = {} for key, value in models.items(): pipelines[value] = pipeline("text-generation", model=value) def respond( message, _: list[tuple[str, str]], model: str, max_new_tokens: int, temperature: float, top_p: float, top_k: int ): yield pipelines[model]( message, max_new_tokens=max_new_tokens, do_sample=True, temperature=temperature, top_p=top_p, top_k=top_k )[0]['generated_text'] """ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface """ demo = gr.ChatInterface( respond, title="Prompt Enhancer Test", type="messages", additional_inputs=[ gr.Radio(list(models.items()), value="pszemraj/distilgpt2-magicprompt-SD", type="value", label="Model"), # gr.Textbox(value="Enhance the provided text so that it is more vibrant and detailed.", label="System prompt"), gr.Slider(minimum=8, maximum=128, value=64, step=8, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider( minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p", ), gr.Slider( minimum=10, maximum=100, value=30, step=5, label="Top-k", ), ], ) if __name__ == "__main__": demo.launch()