Spaces:
Running
Running
Commit
•
92f3bb9
1
Parent(s):
79a4ef8
Upload 2 files
Browse files- app.py +47 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
load_dotenv()
|
3 |
+
import os
|
4 |
+
from langchain.prompts import PromptTemplate
|
5 |
+
from PyPDF2 import PdfReader
|
6 |
+
import google.generativeai as genai
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
10 |
+
|
11 |
+
def get_gemini_response(diff,topic,material):
|
12 |
+
prompt = f"""You are an expert teaching AI model with advanced knowledge of all programming languages.
|
13 |
+
Your task is to generate 10 open-ended questions of {diff} difficulty on the topic:{topic}.
|
14 |
+
The answer to these questions must be present in the following: {material}.\n\n
|
15 |
+
|
16 |
+
<MESSAGE>:|"rate your responses on a scale on 1-10 based on your knowledge. if score is less than 4 generate
|
17 |
+
a new response. do not display the rating." """
|
18 |
+
# template = PromptTemplate(template=prompt,input_variables=['diff','topic','material'])
|
19 |
+
model=genai.GenerativeModel('gemini-pro')
|
20 |
+
response=model.generate_content(prompt)
|
21 |
+
return response.text
|
22 |
+
|
23 |
+
|
24 |
+
st.set_page_config(page_title="Study Mate")
|
25 |
+
|
26 |
+
col1,col2,col3=st.columns(3)
|
27 |
+
with col1:
|
28 |
+
st.subheader("select difficulty")
|
29 |
+
diff=st.selectbox(" ",options=['Easy','Medium','Hard'])
|
30 |
+
|
31 |
+
with col2:
|
32 |
+
st.subheader("Enter Topic")
|
33 |
+
topic=st.text_input("Enter topic of interest:")
|
34 |
+
|
35 |
+
with col3:
|
36 |
+
st.subheader("upload study material:")
|
37 |
+
material=st.file_uploader('daldo bc kuch bhi isme:',type="pdf")
|
38 |
+
text=""
|
39 |
+
if material is not None:
|
40 |
+
# text=''
|
41 |
+
reader=PdfReader(material)
|
42 |
+
for page in reader.pages:
|
43 |
+
text+=page.extract_text()
|
44 |
+
if st.button("generate"):
|
45 |
+
response=get_gemini_response(diff,topic,text)
|
46 |
+
print(response)
|
47 |
+
st.write(response)
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
faiss-cpu
|
4 |
+
langchain
|
5 |
+
PyPDF2
|
6 |
+
langchain_google_genai
|
7 |
+
python-dotenv
|
8 |
+
pypdf
|