File size: 1,671 Bytes
9a41c16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

import gradio as gr
import os
from google import genai
from google.genai import types

client = genai.Client(api_key=os.getenv('GEMINI_API_KEY'))

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, persona):
  system_prompt = personalities[persona]
  response = client.models.generate_content(
      model = "gemini-2.5-flash", contents=question,
      config = types.GenerateContentConfig(systemInstruction=system_prompt)
  )
  return response.text

demo = gr.Interface(fn = study_assistant,
             inputs = [gr.Textbox(label = "Question", lines = 4, placeholder="Ask a Qustion"),
                       gr.Radio(choices = list(personalities.keys()), label = "Persona", value="Friendly")],
             outputs = gr.Textbox(label = "Answer or Explaination", lines = 10),
             title = "Study Assistant",
             description= " Ask a question to get simple explaination.")  

demo.launch(debug = True)