import gradio as gr from huggingface_hub import InferenceClient themes=["Pick a Genre", "thriller", "fantasy", "romance", "sci-fi", "mystery", "fiction"] def reaction(text, theme): modelName= 'HuggingFaceH4/zephyr-7b-beta' thiscontent=f'Give only one {theme} response to this statement: {text}?' messages=[{'role': 'user', 'content': thiscontent}] client=InferenceClient(model=modelName) output=client.chat_completion(messages, max_tokens=100) reaction=output.choices[0].message.content return reaction with gr.Blocks(theme=gr.themes.Citrus()) as demo: with gr.Row(): with gr.Column(): text = gr.Textbox(label="What\'s your idea",scale=1) theme=gr.Dropdown(themes, label="genre") react_btn = gr.Button("Generate",scale=1) output = gr.Textbox(label="Reaction",scale=1) with gr.Column(): react_btn.click(fn=reaction, inputs=[text, theme], outputs=output) demo.launch(debug=True, share=True)