Shivakumar-07 commited on
Commit
cd4e5ff
·
verified ·
1 Parent(s): 6b32fe8

Upload 2 files

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