Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,57 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from function import GetLLMResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# Page configuration
|
| 4 |
st.set_page_config(page_title="Generate Math Quizzes",
|
| 5 |
page_icon="🧮",
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
# from function import GetLLMResponse
|
| 3 |
+
|
| 4 |
+
from langchain_community.llms import OpenAI
|
| 5 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
+
|
| 7 |
+
def get_answers(questions,model):
|
| 8 |
+
st.write("running get answers function answering following questions",questions)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
answer_prompt = ( "I want you to become a teacher answer this specific Question: {questions}. You should gave me a straightforward and consise explanation and answer to each one of them")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
if model == "Open AI":
|
| 15 |
+
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
|
| 16 |
+
answers = llm(answer_prompt)
|
| 17 |
+
# return questions
|
| 18 |
+
|
| 19 |
+
elif model == "Gemini":
|
| 20 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 21 |
+
answers = llm.invoke(answer_prompt)
|
| 22 |
+
answers = answers.content
|
| 23 |
+
# return questions.content
|
| 24 |
+
|
| 25 |
+
return(answers)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def GetLLMResponse(selected_topic_level, selected_topic,num_quizzes, model):
|
| 31 |
+
question_prompt = ('I want you to just generate question with this specification: Generate a {selected_topic_level} math quiz on the topic of {selected_topic}. Generate only {num_quizzes} questions not more and without providing answers.')
|
| 32 |
+
|
| 33 |
+
st.write("running get llm response and print question prompt",question_prompt)
|
| 34 |
+
if model == "Open AI":
|
| 35 |
+
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
|
| 36 |
+
questions = llm(question_prompt)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
elif model == "Gemini":
|
| 40 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 41 |
+
questions = llm.invoke(question_prompt)
|
| 42 |
+
questions = questions.content
|
| 43 |
+
# return questions.content
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
st.write("print questions",questions)
|
| 47 |
+
answers = get_answers(questions,model)
|
| 48 |
+
|
| 49 |
+
st.write(questions,answers)
|
| 50 |
+
return(questions,answers)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
# Page configuration
|
| 56 |
st.set_page_config(page_title="Generate Math Quizzes",
|
| 57 |
page_icon="🧮",
|