Spaces:
Sleeping
Sleeping
streamlit app
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- download_model.py +0 -7
- streamlit_app.py +48 -0
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (1.5 kB). View file
|
|
|
download_model.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
from huggingface_hub import hf_hub_download
|
| 2 |
-
|
| 3 |
-
REPO_ID = "TheBloke/Llama-2-7B-Chat-GGUF"
|
| 4 |
-
FILENAME = "llama-2-7b-chat.Q5_K_M.gguf"
|
| 5 |
-
|
| 6 |
-
hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from app import llm_chain
|
| 3 |
+
import time
|
| 4 |
+
from langchain_community.callbacks.streamlit import (
|
| 5 |
+
StreamlitCallbackHandler,
|
| 6 |
+
)
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
layout="wide",
|
| 9 |
+
page_title="Khatir Bot",
|
| 10 |
+
page_icon="🤖",
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def generate_response(prompt):
|
| 16 |
+
response = llm_chain.invoke(prompt)['text']
|
| 17 |
+
for word in response.split():
|
| 18 |
+
yield word + " "
|
| 19 |
+
time.sleep(0.05)
|
| 20 |
+
|
| 21 |
+
st.title("Khatir Bot")
|
| 22 |
+
|
| 23 |
+
# Initialize chat history
|
| 24 |
+
if "messages" not in st.session_state:
|
| 25 |
+
st.session_state.messages = []
|
| 26 |
+
|
| 27 |
+
# Display chat messages from history on app rerun
|
| 28 |
+
for message in st.session_state.messages:
|
| 29 |
+
with st.chat_message(message["role"]):
|
| 30 |
+
st.markdown(message["content"])
|
| 31 |
+
|
| 32 |
+
# Accept user input
|
| 33 |
+
if prompt := st.chat_input("What is up?"):
|
| 34 |
+
# Add user message to chat history
|
| 35 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 36 |
+
# Display user message in chat message container
|
| 37 |
+
with st.chat_message("user"):
|
| 38 |
+
st.markdown(prompt)
|
| 39 |
+
|
| 40 |
+
# Display assistant response in chat message container
|
| 41 |
+
with st.chat_message("assistant"):
|
| 42 |
+
st_callback = StreamlitCallbackHandler(st.empty())
|
| 43 |
+
response = st.write_stream(llm_chain.invoke(
|
| 44 |
+
{"question":prompt}, {"callbacks": [st_callback]}
|
| 45 |
+
))
|
| 46 |
+
|
| 47 |
+
# Add assistant response to chat history
|
| 48 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|