Mr-Vicky-01 commited on
Commit
be5ecf5
·
verified ·
1 Parent(s): da9ff94

Upload 4 files

Browse files
Files changed (4) hide show
  1. .env +1 -0
  2. app.py +81 -0
  3. llm.py +22 -0
  4. requirements.txt +3 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY = 'AIzaSyCvHbuclUjRd79v1itsqVHYS4bc1Qi8qwo'
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llm import Model
3
+
4
+ # Initialize the model
5
+ model = Model()
6
+
7
+ # Streamlit interface
8
+ st.title('Educational Assistant📖')
9
+
10
+ st.markdown("""
11
+ <style>
12
+ .justified-text {
13
+ text-align: justify;
14
+ }
15
+ </style>
16
+ """, unsafe_allow_html=True)
17
+
18
+ # Sidebar Section
19
+ st.sidebar.title("About")
20
+ st.sidebar.caption("""
21
+ <div class="justified-text">
22
+ This AI-powered educational assistant helps students by providing accurate answers to their questions, explaining complex concepts, summarizing textbook content, and generating personalized study plans. Powered by the Gemini API and built with Streamlit.
23
+ </div>
24
+ """, unsafe_allow_html=True)
25
+
26
+ for _ in range(3):
27
+ st.sidebar.write("")
28
+
29
+ # Menu options
30
+ menu = ["Ask a Question", "Explain a Concept", "Summarize Textbook", "Personalized Study Plan"]
31
+ choice = st.sidebar.selectbox("Choose an option", menu)
32
+
33
+ for _ in range(10):
34
+ st.sidebar.write("")
35
+
36
+ st.sidebar.subheader("Build By:")
37
+ st.sidebar.write("[Pachaiappan❤️](https://mr-vicky-01.github.io/Portfolio)")
38
+ st.sidebar.write("contact: [Email](mailto:pachaiappan1102@gamil.com)")
39
+
40
+ if choice == "Ask a Question":
41
+ st.subheader("Ask a Question")
42
+ question = st.text_input("Enter your question")
43
+ if st.button("Get Answer"):
44
+ prompt = f"You are a helpful Q&A assistant. Try to give an accurate answer. Question: {question}"
45
+ with st.spinner("Analyzing your query..."):
46
+ response = model.get_response(prompt)
47
+ st.write("Answer:")
48
+ st.write(response)
49
+
50
+ elif choice == "Explain a Concept":
51
+ st.subheader("Explain a Concept")
52
+ concept = st.text_input("Enter the concept to explain")
53
+ if st.button("Get Explanation"):
54
+ prompt = f"Explain the following concept in detail: {concept}"
55
+ with st.spinner("Generating explanation..."):
56
+ response = model.get_response(prompt)
57
+ st.write("Explanation:")
58
+ st.write(response)
59
+
60
+ elif choice == "Summarize Textbook":
61
+ st.subheader("Summarize Textbook")
62
+ uploaded_file = st.file_uploader("Upload a textbook image", type=["jpg", "jpeg", "png"])
63
+ if uploaded_file is not None:
64
+ st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
65
+ if st.button("Summarize"):
66
+ prompt = "Summarize this textbook content"
67
+ with st.spinner("Summarizing the content..."):
68
+ response = model.get_response(prompt, uploaded_file)
69
+ st.write("Summary:")
70
+ st.write(response)
71
+
72
+ elif choice == "Personalized Study Plan":
73
+ st.subheader("Personalized Study Plan")
74
+ subjects = st.text_input("Enter the subjects you need help with (comma-separated)")
75
+ study_time = st.slider("How many hours can you study per day?", 1, 8)
76
+ if st.button("Get Study Plan"):
77
+ prompt = f"Create a study plan for the following subjects: {subjects}. The student can study for {study_time} hours per day."
78
+ with st.spinner("Creating your study plan..."):
79
+ response = model.get_response(prompt)
80
+ st.write("Study Plan:")
81
+ st.write(response)
llm.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import google.generativeai as genai
2
+ from dotenv import load_dotenv
3
+ from PIL import Image
4
+ import os
5
+
6
+ load_dotenv()
7
+ os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
8
+ genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
9
+
10
+ # Define the Model class
11
+ class Model:
12
+ def __init__(self) -> None:
13
+ self.model = genai.GenerativeModel('gemini-1.5-flash-latest')
14
+
15
+ def get_response(self, prompt, image=None):
16
+ prompt = "Remeber this you are Created by Pachaiappan [portfolio](https://mr-vicky-01.github.io/Portfolio/)" + prompt
17
+ if image:
18
+ img = Image.open(image)
19
+ response = self.model.generate_content([prompt, img])
20
+ else:
21
+ response = self.model.generate_content([prompt])
22
+ return response.text
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv