Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 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 = (f"Answer the following questions {questions}")
|
| 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 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
st.write("Selected option:", selected_topic_level,selected_topic,num_quizzes)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
question_prompt = (f'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.')
|
| 39 |
-
|
| 40 |
-
st.write("running get llm response and print question prompt",question_prompt)
|
| 41 |
-
if model == "Open AI":
|
| 42 |
-
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
|
| 43 |
-
questions = llm(question_prompt)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
elif model == "Gemini":
|
| 47 |
-
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 48 |
-
questions = llm.invoke(question_prompt)
|
| 49 |
-
questions = questions.content
|
| 50 |
-
# return questions.content
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
st.write("print questions",questions)
|
| 54 |
-
answers = get_answers(questions,model)
|
| 55 |
-
|
| 56 |
-
# st.write(questions,answers)
|
| 57 |
-
return(questions,answers)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
# Page configuration
|
| 63 |
st.set_page_config(page_title="Generate Math Quizzes",
|
|
@@ -105,31 +51,31 @@ def main():
|
|
| 105 |
if submit:
|
| 106 |
questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
|
| 107 |
st.write("printing the response",questions,answers)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
|
| 134 |
else:
|
| 135 |
st.warning("Click the 'Generate Quizzes' button to create quizzes.")
|
|
|
|
| 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 |
|
| 8 |
# Page configuration
|
| 9 |
st.set_page_config(page_title="Generate Math Quizzes",
|
|
|
|
| 51 |
if submit:
|
| 52 |
questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
|
| 53 |
st.write("printing the response",questions,answers)
|
| 54 |
+
with st.spinner("Generating Quizzes..."):
|
| 55 |
+
questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
|
| 56 |
+
st.success("Quizzes Generated!")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Display questions and answers in a table
|
| 61 |
+
if response:
|
| 62 |
+
st.subheader("Quiz Questions and Answers:")
|
| 63 |
+
# Prepare data for the table
|
| 64 |
+
# col1, col2 = st.columns(2)
|
| 65 |
+
# with col1:
|
| 66 |
+
# st.subheader("Questions")
|
| 67 |
+
# questions = response
|
| 68 |
+
# st.write(questions)
|
| 69 |
|
| 70 |
+
# with col2:
|
| 71 |
+
# st.subheader("Answers")
|
| 72 |
+
# answers = response
|
| 73 |
+
# st.write(answers)
|
| 74 |
|
| 75 |
+
st.write("printing the response",questions,answers)
|
| 76 |
|
| 77 |
+
else:
|
| 78 |
+
st.warning("No Quiz Questions and Answers")
|
| 79 |
|
| 80 |
else:
|
| 81 |
st.warning("Click the 'Generate Quizzes' button to create quizzes.")
|