LocoLama2 / app.py
DrDomedag's picture
Initial commit.
3a8a5cf
raw
history blame
1.62 kB
import streamlit as st
from huggingface_hub import InferenceClient
import random
st.title("ChatGPT-like clone")
#model_name = "unsloth/Llama-3.2-1B-Instruct"
model_name = "HuggingFaceH4/zephyr-7b-beta"
client = InferenceClient(model_name)
# Session state to hold chat history
if "messages" not in st.session_state:
st.session_state.messages = [{"role": "system", "content": "You are a helpful assistant."}]
# Display the chat history
for message in st.session_state.messages:
if message["role"] == "user":
st.markdown(f"**You:** {message['content']}")
else:
st.markdown(f"**Zephyr 7B:** {message['content']}")
# User input
user_input = st.text_input("Type your message here...", key="user_input")
# On submit
if st.button("Send"):
if user_input.strip():
# Add user's message to the chat history
st.session_state.messages.append({"role": "user", "content": user_input})
# Query the model
with st.spinner("Zephyr is thinking..."):
response = client.text_generation(user_input)
#assistant_reply = response.get("generated_text", "").strip()
assistant_reply = response.strip()
# Add the model's reply to the chat history
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
# Clear the input box
st.session_state.user_input = ""
# Instructions for the user
st.sidebar.title("Instructions")
st.sidebar.info(
"""
- Type your message in the input box and press "Send."
- Responses are powered by the HuggingFace `zephyr-7b-beta` model.
"""
)