hemanth07k commited on
Commit
fc195dd
·
verified ·
1 Parent(s): 0caa362

Upload 2 files

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