SBDeploy/Study_Assistant
0
1import gradio as gr2from google import genai3from google.genai import types4import os5 6client = genai.Client(api_key=os.getenv('GOOGLE_API_KEY'))7 8personalities = {9 "Friendly": "You are a warm, encouraging study buddy who explains things with kindness and humor. Keep it simple.",10 "Blunt": "You are a no-nonsense tutor who is direct, efficient, and expects focus.",11 "Academic": "You are a precise assistant who is structured and avoids fluff."12}13 14def study_assistant(question, persona):15 system_prompt = personalities[persona]16 17 full_prompt = f"""18 Act with the following personality: {system_prompt}19 Answer the student's question clearly:20 {question}21 """22 23 response = client.models.generate_content(24 model="gemini-2.0-flash",25 contents=full_prompt26 )27 return response.text28 29demo = gr.Interface(30 fn=study_assistant,31 inputs=[32 gr.Textbox(lines=4, placeholder="Ask a question...", label="Question"),33 gr.Radio(choices=list(personalities.keys()), value="Friendly", label="Personality")34 ],35 outputs=gr.Textbox(lines=10, label="Response"),36 title="Study Assistant",37 description="Ask a question and get an answer from your AI study assistant with a chosen personality."38)39 40demo.launch(debug=True)41 