import os import gradio as gr from google import genai # Secure API key from Hugging Face Secrets client = genai.Client( api_key=os.getenv("GEMINI_API_KEY") ) # ---------------- AI CALL ---------------- def ask(prompt): try: response = client.models.generate_content( model="gemini-2.5-flash", contents=prompt ) return response.text except Exception as e: return f"Error: {str(e)}" # ---------------- PROMPTS ---------------- def zero_shot(task): return task def few_shot(task): return f""" Example: Q: What is AI? A: AI is the simulation of human intelligence in machines. Now answer: Q: {task} A: """ def cot(task): return f""" Solve step by step: Task: {task} Step 1: Step 2: Final Answer: """ # ---------------- MAIN FUNCTION ---------------- def run_dashboard(task): if not task.strip(): return "Please enter a prompt.", "", "" z = ask(zero_shot(task)) f = ask(few_shot(task)) c = ask(cot(task)) return z, f, c # ---------------- GRADIO UI ---------------- demo = gr.Interface( fn=run_dashboard, inputs=gr.Textbox( label="✨ Enter Your Prompt", placeholder="Example: Explain machine learning in simple terms", lines=3 ), outputs=[ gr.Textbox(label="🔷 Zero-Shot Response"), gr.Textbox(label="🟣 Few-Shot Response"), gr.Textbox(label="🟢 Chain-of-Thought Response"), ], title="Prompt Engineering Explorer", description=""" Compare how different prompting styles (Zero-shot, Few-shot, Chain-of-Thought) affect AI-generated responses. """, theme=gr.themes.Soft( primary_hue="cyan", secondary_hue="emerald", neutral_hue="slate" ), allow_flagging="never" ) demo.launch()