Study_Assistant / app.py
sriharshi's picture
Update app.py
e8f42eb verified
Raw History Blame Contribute Delete
1.36 kB
import os
from google import genai
from google.genai import types
import gradio as gr
client = genai.Client(api_key = os.getenv("GEMINI_API_KEY"))
personalities = {
"Friendly" : "you are a friendly, enthusiastic, and highly encoraging study assistant. use simple language andfrequent encouragement.",
"Academic" : "you are a strictly acadamic, highly detailed, and professional university professor who is my study assistant. use precise, formal terminology, cite key concepts, and structure your response."
}
def study_assistant(question, persona):
system_prompt = personalities[persona]
response = client.models.generate_content(
model = "gemini-2.5-flash",
config = types.GenerateContentConfig(
system_instruction = system_prompt,
temperature = 0.4,
max_output_tokens = 2000,
),
contents = question
)
return response.text
demo = gr.Interface(
fn = study_assistant,
inputs = [gr.Textbox(label="Question", lines = 4, placeholder="Ask a question.."),
gr.Dropdown(choices=list(personalities.keys()), value= "Friendly", label="Personality" )],
outputs= gr.Textbox(lines = 10, label = "Response"),
title= "Study Assistant",
description= "Ask a question and get an answer from your AI study assistant with a choosen personality"
)
demo.launch(debug = True)