Spaces:
Sleeping
Sleeping
Download app.py from AjithReddy/StudyAssistant: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/AjithReddy/StudyAssistant/resolve/main/app.py
- Command line
-
hf download hf://spaces/AjithReddy/StudyAssistant/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AjithReddy/StudyAssistant/resolve/main/app.py
1.69 kB
| import os | |
| from google import genai | |
| from google.genai import types | |
| import gradio as gr | |
| client=genai.Client(api_key = os.getenv('GEMINI_API_KEY')) | |
| personalities = { | |
| "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.", | |
| "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." | |
| } | |
| def study_assistant(question,persona): | |
| system_prompt = personalities[persona] | |
| response = client.models.generate_content( | |
| model="gemini-2.5-flash", | |
| config= types.GenerateContentConfig( | |
| system_instruction = system_prompt, | |
| temperature=0.4, | |
| max_output_tokens=1000 | |
| ), | |
| contents = question | |
| ) | |
| return response.text | |
| demo = gr.Interface( | |
| fn=study_assistant, | |
| inputs=[ | |
| gr.Textbox(label="question", lines=4, placeholder="Ask a Question.."), | |
| gr.Dropdown(choices=list(personalities.keys()), value="Friendly", label="personality") | |
| ], | |
| outputs=gr.Textbox(label="Explanation", lines=10), | |
| title="Study Assistant", | |
| description="Ask a question and get an answer from your AI study assistant with a chosen personality." | |
| ) | |
| demo.launch(debug=True) | |