abixndh commited on
Commit
6dcda2c
·
verified ·
1 Parent(s): 4a220c8

initial commit

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from google import genai
3
+ from google.genai import types
4
+ import gradio as gr
5
+
6
+ client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
7
+
8
+ personalities = {
9
+ "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.",
10
+ "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.The respose should be elaborate as well as concise.Strike a judicious balance. Always ask a follow-up question to check understanding."
11
+ }
12
+
13
+ def study_assistant(question, persona):
14
+ system_prompt = personalities[persona]
15
+ response=client.models.generate_content(
16
+ model="gemini-2.5-flash",
17
+ config=types.GenerateContentConfig(
18
+ system_instruction=system_prompt,
19
+ temperature=0.4,
20
+ max_output_tokens=2000,
21
+ ),
22
+ contents=question
23
+ )
24
+ return response.text
25
+
26
+ demo= gr.Interface(
27
+ fn=study_assistant,
28
+ inputs=[gr.Textbox(label="Question",lines=4,placeholder="Ask a question..."),
29
+ gr.Dropdown(choices=list(personalities.keys()),value="Friendly",label="personalities")],
30
+ outputs=[gr.Textbox(label="response",lines=10)],
31
+ title="UR Study Assistant",
32
+ description= "Ask a question to get simple explanation from AI along with analogies and real world examples"
33
+ )
34
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ google-genai
2
+ gradio