Spaces:
Sleeping
Sleeping
initial commit
Browse files- app.py +40 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google import genai
|
| 2 |
+
from google.colab import userdata
|
| 3 |
+
from google.genai import types
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
client = genai.Client(api_key=userdata.get("GOOGLE_API_KEY"))
|
| 9 |
+
|
| 10 |
+
personalities = {
|
| 11 |
+
"Friendly":
|
| 12 |
+
"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",
|
| 13 |
+
"Academic":
|
| 14 |
+
"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. Always ask a follow-up question to check understanding"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
def study_assistant(question, persona):
|
| 18 |
+
system_prompt = personalities[persona]
|
| 19 |
+
|
| 20 |
+
response = client.models.generate_content(
|
| 21 |
+
model="gemini-2.5-flash",
|
| 22 |
+
config=types.GenerateContentConfig(
|
| 23 |
+
system_instruction=system_prompt,
|
| 24 |
+
temperature=0.4,
|
| 25 |
+
max_output_tokens=600
|
| 26 |
+
),
|
| 27 |
+
contents=question
|
| 28 |
+
)
|
| 29 |
+
return response.text
|
| 30 |
+
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=study_assistant,
|
| 33 |
+
inputs=[gr.Textbox(label="Question", lines=4, placeholder= "Ask a question..."),
|
| 34 |
+
gr.Dropdown(choices=list(personalities.keys()), value="Friendly", label="Personality")],
|
| 35 |
+
outputs= gr.Textbox(label="Explaination", lines=10),
|
| 36 |
+
title="Study Assistant",
|
| 37 |
+
description="Ask a question to get simple explaination from AI along with analogies and real world examples"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
google-genai
|
| 2 |
+
gradio
|