Spaces:
Runtime error
Runtime error
initial commit
Browse files- app.py +35 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from google import genai
|
| 3 |
+
from google.genai import types
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
client=genai.Client(api_key=os.getenv("AIzaSyDxMXux4i5q7d0NB5z8Z1VYS6WODEIWOls"))
|
| 7 |
+
|
| 8 |
+
personalities = {
|
| 9 |
+
"Friendly": "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.",
|
| 10 |
+
"Academic": "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."
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
def study_assistant(question,persona):
|
| 14 |
+
system_prompt=personalities[persona]
|
| 15 |
+
response = client.models.generate_content(
|
| 16 |
+
model="gemini-2.5-flash",
|
| 17 |
+
config=types.GenerateContentConfig(
|
| 18 |
+
system_instruction=system_prompt,
|
| 19 |
+
),
|
| 20 |
+
contents=question
|
| 21 |
+
)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=study_assistant,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Textbox(lines=4, placeholder="Ask a question...", label="Question"),
|
| 29 |
+
gr.Radio(choices=list(personalities.keys()), value="Friendly", label="Personality")
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Textbox(lines=10, label="Response"),
|
| 32 |
+
title="Study Assistant",
|
| 33 |
+
description="Ask a question and get an answer from your AI study assistant with a chosen personality."
|
| 34 |
+
)
|
| 35 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
google-genai
|