Files changed (1) hide show
  1. app.py +58 -40
app.py CHANGED
@@ -1,48 +1,66 @@
1
- #genai.configure(api_key="AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY")
 
2
 
3
- import streamlit as st
4
- import google.generativeai as genai
5
 
6
- # Configure the API key for Gemini AI
7
- genai.configure(api_key="AIzaSyD8tAz466UNCkLl83WBT05imim-JYL5Gr4")
 
 
8
 
9
- # AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY
10
- model = genai.GenerativeModel("gemini-1.5-flash")
 
 
11
 
12
- # Streamlit App layout
13
- st.title("AI-Powered Python Code Assistant")
14
- st.markdown("This assistant can help you with code suggestions, debugging, and reusable snippets using Gemini AI.")
 
 
15
 
16
- # Sidebar
17
- st.sidebar.header("Select Feature")
18
- feature = st.sidebar.selectbox(
19
- "Choose what you need help with:",
20
- ["Code Suggestions", "Code Debugging", "Reusable Code Snippets", "General Code Query"]
21
- )
 
22
 
23
- # Input box for user to type code or query
24
- user_input = st.text_area("Enter your Python code or query here:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # Button to trigger the AI response
27
- if st.button("Get AI Suggestions"):
28
 
29
- # Generate response based on selected feature
30
- if feature == "Code Suggestions":
31
- prompt = f"Suggest code completion for the following Python code:\n{user_input}"
32
- elif feature == "Code Debugging":
33
- prompt = f"Find and fix the bugs in the following Python code:\n{user_input}"
34
- elif feature == "Reusable Code Snippets":
35
- prompt = f"Provide reusable Python code snippets related to: {user_input}"
36
- else:
37
- prompt = f"Provide an explanation or advice on this Python code/query:\n{user_input}"
38
-
39
- # Get response from Gemini AI model
40
- response = model.generate_content(prompt)
41
-
42
- # Display AI's response in the app
43
- st.subheader("AI's Response:")
44
- st.code(response.text, language="python")
45
-
46
- # Optionally, you can add a footer or additional features here
47
- st.markdown("---")
48
- st.markdown("Powered by **Streamlit** and **Google Gemini AI**")
 
1
+ # app.py
2
+ import gradio as gr
3
 
4
+ SUBJECTS = ["Mathematics", "English", "Kiswahili", "Physics", "Chemistry", "Biology", "Islamic Studies"]
 
5
 
6
+ WELCOME_MD = """
7
+ # Elimuhub Tutor 🀝
8
+ **Elimuhub Education Consultants** β€” Quick demo tutor (mobile friendly).
9
+ Contact: +254 731-838-387β€’ elimuhubconsultant@gmail.com
10
 
11
+ Type your question below or try quick commands:
12
+ - Say "generate quiz: subject, level, n" e.g., `generate quiz: math, KCSE, 3`
13
+ - Ask: "How do I solve quadratic equations?"
14
+ """
15
 
16
+ def generate_quiz(subject="General", level="Any", n=3):
17
+ qlist = []
18
+ for i in range(1, n+1):
19
+ qlist.append(f"{i}. Sample {level} {subject} question #{i}?")
20
+ return "\n".join(qlist)
21
 
22
+ def respond(user_message, history):
23
+ if history is None:
24
+ history = []
25
+ msg = (user_message or "").strip()
26
+ if not msg:
27
+ return history, ""
28
+ low = msg.lower()
29
 
30
+ if any(greet in low for greet in ["hi", "hello", "hey", "salaam", "assalamu"]):
31
+ bot = "Hello! πŸ‘‹ I'm Elimuhub's demo tutor. Tell me the subject and topic (e.g., 'math algebra')."
32
+ elif low.startswith("generate quiz:"):
33
+ try:
34
+ rest = low.split("generate quiz:",1)[1].strip()
35
+ parts = [p.strip() for p in rest.split(",")]
36
+ subj = parts[0].title() if len(parts) > 0 and parts[0] else "General"
37
+ level = parts[1].upper() if len(parts) > 1 and parts[1] else "Any"
38
+ num = int(parts[2]) if len(parts) > 2 and parts[2].isdigit() else 3
39
+ except Exception:
40
+ subj, level, num = "General", "Any", 3
41
+ bot = generate_quiz(subj, level, num)
42
+ elif any(s.lower() in low for s in SUBJECTS):
43
+ bot = ("Great β€” you asked about a subject I recognize. "
44
+ "Please give the specific topic (e.g., algebra, verb tenses), and I'll give step-by-step help.")
45
+ elif "kcse" in low or "kcpe" in low or "igcse" in low or "ib" in low:
46
+ bot = "I can give exam-style tips and sample questions. Tell me the subject and the topic."
47
+ else:
48
+ # simple demo answer: echo plus tips
49
+ bot = ("Thanks β€” here's a quick answer guide:\n\n"
50
+ f"> You asked: {user_message}\n\n"
51
+ "I'm a demo assistant. For clearer help, say the subject and topic (e.g., 'math: quadratic formula').")
52
 
53
+ history.append((user_message, bot))
54
+ return history, ""
55
 
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown(WELCOME_MD)
58
+ chatbot = gr.Chatbot(elem_id="chatbot", label="Elimuhub Tutor")
59
+ with gr.Row():
60
+ txt = gr.Textbox(show_label=False, placeholder="Type your question here and press Enter...")
61
+ send = gr.Button("Send")
62
+ send.click(respond, inputs=[txt, chatbot], outputs=[chatbot, txt])
63
+ txt.submit(respond, inputs=[txt, chatbot], outputs=[chatbot, txt])
64
+
65
+ if __name__ == "__main__":
66
+ demo.launch()