File size: 1,856 Bytes
68a198c
f7ddf2b
1ae0ea8
f7ddf2b
 
 
9dcc7aa
f7ddf2b
 
 
68a198c
347c176
68a198c
43f0cc0
 
68a198c
 
 
 
 
43f0cc0
68a198c
 
 
 
 
 
 
 
 
 
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
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)