Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +37 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
from google import genai
|
| 5 |
+
from google.genai import types
|
| 6 |
+
|
| 7 |
+
client = genai.Client(api_key=os.getenv('GEMINI_API_KEY'))
|
| 8 |
+
|
| 9 |
+
personalities = {
|
| 10 |
+
"Friendly": """You are a friendly, enthusiastic, and highly encouraging Study Assistant.
|
| 11 |
+
Your goal is to break down complex concepts into simple, beginner-friendly explanations.
|
| 12 |
+
Use analogies and real-world examples that beginners can relate to. Always ask a
|
| 13 |
+
follow-up question to check understanding""",
|
| 14 |
+
"Academic": """You are a strictly academic, highly detailed, and professional university
|
| 15 |
+
Professor. Use precise, formal terminology, cite key concepts and structure your
|
| 16 |
+
response. Your goal is to break down complex concepts into simple, beginner-friendly
|
| 17 |
+
explanations. Use analogies and real-world examples that
|
| 18 |
+
beginners can relate to. Always ask a follow-up question to check understanding"""
|
| 19 |
+
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
def study_assistant(question, persona):
|
| 23 |
+
system_prompt = personalities[persona]
|
| 24 |
+
response = client.models.generate_content(
|
| 25 |
+
model = "gemini-2.5-flash", contents=question,
|
| 26 |
+
config = types.GenerateContentConfig(systemInstruction=system_prompt)
|
| 27 |
+
)
|
| 28 |
+
return response.text
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(fn = study_assistant,
|
| 31 |
+
inputs = [gr.Textbox(label = "Question", lines = 4, placeholder="Ask a Qustion"),
|
| 32 |
+
gr.Radio(choices = list(personalities.keys()), label = "Persona", value="Friendly")],
|
| 33 |
+
outputs = gr.Textbox(label = "Answer or Explaination", lines = 10),
|
| 34 |
+
title = "Study Assistant",
|
| 35 |
+
description= " Ask a question to get simple explaination.")
|
| 36 |
+
|
| 37 |
+
demo.launch(debug = True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
google-genai
|