import gradio as gr import random import openai def tell_us_about_yo_momma(category, topic): openAI_key = os.getenv('my_openAI_key') if openAI_key.strip()=='': return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys' prompt = "" prompt = f"Tell us a yo momma joke about her {category} and {topic}" completions = openai.Completion.create( engine=engine, prompt=prompt, max_tokens=512, n=1, stop=None, temperature=0.6, ) message = completions.choices[0].text return message def launch_demo(): categories = [ "Appearance", "Weight", "Intelligence", "Age", "Financial Status", "Cleanliness/Hygiene", "Lifestyle", "Occupation", "Taste/Culture", "Cooking Skills" ] topics = [ "Holidays", "Plants", "Animals", "Countries", "Pop Culture", "Religion", "Lifestyle", "Environment", "Technology", "Sports", "Music", "Space/Astronomy", "Food and Cooking", "History", "Travel", "Education", "Health and Fitness", "Movies/TV Shows" ] dropdown = gr.components.Dropdown(categories, label="Category") text_input = gr.components.Textbox(label="Topic") output = gr.components.Textbox(label="Lolz") # some random pre-seeded options rando_choice = random.choice(categories) rando_topic = random.choice(topics) rando_choice_b = random.choice(categories) rando_topic_b = random.choice(topics) rando_choice_c = random.choice(categories) rando_topic_c = random.choice(topics) examples = [ [rando_choice, rando_topic], [rando_choice_b, rando_topic_b], [rando_choice_c, rando_topic_c], ] gr.Interface( fn=tell_us_about_yo_momma, inputs=[dropdown, text_input], outputs=output, examples=examples, title="Yo Momma's so Generative...", description="How Generative is Yo Momma? Select Category, enter Topic, and click Submit to find out. You can also try a supplied example.", theme="default", ).launch() launch_demo()