Parkbong7 commited on
Commit
488fed6
·
verified ·
1 Parent(s): e7de99f

initial commit

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