dinesh-07-dev's picture
Update app.py
1ae0ea8 verified
Raw History Blame Contribute Delete
1.86 kB
import os
import sys
import subprocess
try:
from google.genai import Client
from google.genai import types
except:
suprocess.checl_call([sys.executable('-m', 'pip', 'install', 'google-genai')])
from google.genai import Client
from google.genai import types
import gradio as gr
client = Client(api_key = os.getenv("study"))
personalities = {
"Friendly": """You are a friendly, enthusiastic, and highly encouraging Study Assistant. Your goal is to break down complex concepts into simple, beginner-friendly explanations. Use analogies and real-world examples that beginners can relate to. Always ask a follow-up question to check understanding.""",
"Academic": """You are a strictly academic, highly detailed, and professional university Professor. Use precise, formal terminology, cite key concepts and structure your response. Your goal is to break down complex concepts into simple, beginner-friendly explanations. Use analogies and real-world examples that beginners can relate to. Always ask a follow-up question to check understanding."""
}
def study_assistant(question,personality):
prompt = personalities[personality]
response = client.models.generate_content(
model = "gemini-2.5-flash",
config = types.GenerateContentConfig(system_instruction = 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 any question..."), gr.Radio(label = "personality", choices = list(personalities.keys()), value = "Friendly")],
outputs = gr.Textbox(label = "response", lines = 10), title = "Study Assistant",
description = "Ask the question and get the answer to out AI and get use of it..."
)
demo.launch(debug = True)