Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
from langchain import HuggingFaceHub,PromptTemplate,LLMChain
|
| 3 |
|
| 4 |
from getpass import getpass
|
| 5 |
#HUGGINGFACE_API_TOKEN=getpass()
|
| 6 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "Token"
|
|
|
|
| 7 |
model_id="mistralai/Mistral-7B-Instruct-v0.2"
|
| 8 |
conv_model=HuggingFaceHub(huggingfacehub_api_token=os.environ['HUGGINGFACEHUB_API_TOKEN'],
|
| 9 |
repo_id=model_id,
|
| 10 |
-
model_kwargs={"temperature":0.
|
| 11 |
|
| 12 |
def answer_question(question):
|
| 13 |
prompt = PromptTemplate( input_variables=['question'],
|
| 14 |
-
template="""You are a logical and a numerical question solver.Could you please answer this question ?{question}
|
|
|
|
| 15 |
""")
|
| 16 |
conv_chain = LLMChain(llm=conv_model, prompt=prompt, verbose=True,output_key="Answer")
|
| 17 |
response = conv_chain({'question':question})
|
| 18 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
print("nothing given")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import os
|
| 3 |
from langchain import HuggingFaceHub,PromptTemplate,LLMChain
|
| 4 |
|
| 5 |
from getpass import getpass
|
| 6 |
#HUGGINGFACE_API_TOKEN=getpass()
|
| 7 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "Token"
|
| 8 |
+
|
| 9 |
model_id="mistralai/Mistral-7B-Instruct-v0.2"
|
| 10 |
conv_model=HuggingFaceHub(huggingfacehub_api_token=os.environ['HUGGINGFACEHUB_API_TOKEN'],
|
| 11 |
repo_id=model_id,
|
| 12 |
+
model_kwargs={"temperature":0.2,"max_new_tokens":5000})
|
| 13 |
|
| 14 |
def answer_question(question):
|
| 15 |
prompt = PromptTemplate( input_variables=['question'],
|
| 16 |
+
template="""You are a logical and a numerical question solver.Could you please answer this question ? {question}
|
| 17 |
+
Show all the steps in details to solve the problem.
|
| 18 |
""")
|
| 19 |
conv_chain = LLMChain(llm=conv_model, prompt=prompt, verbose=True,output_key="Answer")
|
| 20 |
response = conv_chain({'question':question})
|
| 21 |
return response
|
| 22 |
+
|
| 23 |
+
st.title("Zero Shot Question Answering")
|
| 24 |
+
input=st.text_input("Input: ",key="input")
|
| 25 |
+
submit=st.button("Ask the question")
|
| 26 |
+
if submit and input:
|
| 27 |
+
response=answer_question(input)
|
| 28 |
+
st.write(response['Answer'])
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
print("nothing given")
|