Spaces:
Sleeping
Sleeping
Srinivas T B commited on
Commit ·
b2fc3d2
1
Parent(s): bb59f22
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from langchain import HuggingFaceHub
|
| 5 |
+
from apikey import apikey
|
| 6 |
+
from langchain import PromptTemplate, LLMChain
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Set Hugging Face Hub API token
|
| 10 |
+
# Make sure to store your API token in the `apikey_hungingface.py` file
|
| 11 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = apikey
|
| 12 |
+
|
| 13 |
+
# Set up the language model using the Hugging Face Hub repository
|
| 14 |
+
repo_id = "tiiuae/falcon-7b-instruct"
|
| 15 |
+
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.3, "max_new_tokens": 2000})
|
| 16 |
+
|
| 17 |
+
# Set up the prompt template
|
| 18 |
+
template = """
|
| 19 |
+
I'm an artificial intelligence assistant.
|
| 20 |
+
I give you helpful, detailed, and polite answers to your questions
|
| 21 |
+
Question: {question}\n\nAnswer: Hmmmm, ok let's think step by step."""
|
| 22 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 23 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
| 24 |
+
|
| 25 |
+
# Create the Streamlit app
|
| 26 |
+
def main():
|
| 27 |
+
|
| 28 |
+
st.title("savbot - your helpful assistant <3 by srini")
|
| 29 |
+
|
| 30 |
+
# Get user input
|
| 31 |
+
question = st.text_input("what's up?")
|
| 32 |
+
|
| 33 |
+
# Generate the response
|
| 34 |
+
if st.button("help me out!"):
|
| 35 |
+
with st.spinner("here you go......"):
|
| 36 |
+
response = llm_chain.run(question)
|
| 37 |
+
st.success(response)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
main()
|