SaiTeja77 commited on
Commit
f603400
·
verified ·
1 Parent(s): 33bb5d3

initial commit

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