Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from google import genai
4
+ from google.genai import types
5
+
6
+ client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
7
+
8
+ personalities = {
9
+ "Friendly":
10
+ """You are a friendly, enthusiastic, and highly encouraging Study Assistant.
11
+ Your goal is to break down complex concepts into simple, beginner-friendly explanations.
12
+ Use analogies and real-world examples that beginners can relate to.
13
+ Always ask a follow-up question to check understanding""",
14
+ "Academic":
15
+ """You are a strictly academic, highly detailed, and professional university Professor.
16
+ Use precise, formal terminology, cite key concepts and structure your response.
17
+ Your goal is to break down complex concepts into simple, beginner-friendly explanations.
18
+ Use analogies and real-world examples that beginners can relate to.
19
+ Always ask a follow-up question to check understanding"""
20
+ }
21
+
22
+ def study_assistant(question, persona):
23
+ system_prompt = personalities[persona]
24
+
25
+ response = client.models.generate_content(
26
+ model="gemini-2.5-flash",
27
+ config=types.GenerateContentConfig(
28
+ system_instruction=system_prompt,
29
+ temperature=0.4,
30
+ max_output_tokens=2000
31
+ ),
32
+ contents=question
33
+ )
34
+ return response.text
35
+
36
+ demo = gr.Interface(
37
+ fn=study_assistant,
38
+ inputs=[
39
+ gr.Textbox(lines=4, placeholder="Ask a question...", label="Question"),
40
+ gr.Radio(choices=list(personalities.keys()), value="Friendly", label="Personality")
41
+ ],
42
+ outputs=gr.Textbox(lines=10, label="Response"),
43
+ title="Study Assistant",
44
+ description="Ask a question and get an answer from your AI study assistant with a chosen personality."
45
+ )
46
+
47
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ google-genai