Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,58 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
st.warning("No Quiz Questions and Answers")
|
| 60 |
-
|
| 61 |
-
else:
|
| 62 |
-
st.warning("Click the 'Generate Quizzes' button to create quizzes.")
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.llms import CTransformers
|
| 3 |
+
from langchain.chains import LLMChain
|
| 4 |
+
from langchain.chains import SequentialChain
|
| 5 |
+
from langchain.llms import HuggingFaceHub
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
# load_dotenv();
|
| 9 |
+
config = {'max_new_tokens': 512, 'temperature': 0.6}
|
| 10 |
+
|
| 11 |
+
# Create function for app
|
| 12 |
+
def GetLLMResponse(selected_topic_level,
|
| 13 |
+
selected_topic,
|
| 14 |
+
num_quizzes):
|
| 15 |
+
|
| 16 |
+
# Calling llama model
|
| 17 |
+
# llm = CTransformers(model="D:\Code Workspace\DL Model\llama-2-7b-chat.ggmlv3.q8_0.bin",
|
| 18 |
+
# model_type = 'llama',
|
| 19 |
+
# config = config)
|
| 20 |
+
|
| 21 |
+
# llm = CTransformers(model='TheBloke/Llama-2-7B-Chat-GGML',
|
| 22 |
+
# model_file = 'llama-2-7b-chat.ggmlv3.q8_0.bin',
|
| 23 |
+
# model_type = 'llama',
|
| 24 |
+
# config = config)
|
| 25 |
+
|
| 26 |
+
llm = HuggingFaceHub(
|
| 27 |
+
repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 28 |
+
model_kwargs = config
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
## Create LLM Chaining
|
| 32 |
+
questions_template = "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. The Question should not in image format/link"
|
| 33 |
+
questions_prompt = PromptTemplate(input_variables=["selected_topic_level", "selected_topic", "num_quizzes"],
|
| 34 |
+
template=questions_template)
|
| 35 |
+
questions_chain = LLMChain(llm= llm,
|
| 36 |
+
prompt = questions_prompt,
|
| 37 |
+
output_key = "questions")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
answer_template = "I want you to become a teacher answer this specific Question:\n {questions}\n\n. You should gave me a straightforward and consise explanation and answer to each one of them"
|
| 41 |
+
answer_prompt = PromptTemplate(input_variables = ["questions"],
|
| 42 |
+
template = answer_template)
|
| 43 |
+
answer_chain = LLMChain(llm = llm,
|
| 44 |
+
prompt = answer_prompt,
|
| 45 |
+
output_key = "answer")
|
| 46 |
+
|
| 47 |
+
## Create Sequential Chaining
|
| 48 |
+
seq_chain = SequentialChain(chains = [questions_chain, answer_chain],
|
| 49 |
+
input_variables = ['selected_topic_level', 'selected_topic', 'num_quizzes'],
|
| 50 |
+
output_variables = ['questions', 'answer'])
|
| 51 |
+
|
| 52 |
+
response = seq_chain({'selected_topic_level': selected_topic_level,
|
| 53 |
+
'selected_topic': selected_topic,
|
| 54 |
+
'num_quizzes' : num_quizzes})
|
| 55 |
+
|
| 56 |
+
## Generate the response from the llama 2 model
|
| 57 |
+
print(response)
|
| 58 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|