Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def fetch_response(prompt):
|
| 2 |
"""
|
| 3 |
Fetch full text response from the HF Inference Endpoint using the InferenceClient.
|
|
@@ -23,3 +41,35 @@ def fetch_response(prompt):
|
|
| 23 |
break
|
| 24 |
partial_text += response.token.text
|
| 25 |
yield response.token.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Constants
|
| 6 |
+
SPACE_URL = "https://z7svds7k42bwhhgm.us-east-1.aws.endpoints.huggingface.cloud"
|
| 7 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 8 |
+
DUBS_PATH = "🐾" # Optional: Replace with an avatar path if needed
|
| 9 |
+
|
| 10 |
+
# Streamlit Configuration
|
| 11 |
+
st.set_page_config(page_title="Chatbot Test", page_icon="🤖", layout="centered")
|
| 12 |
+
|
| 13 |
+
client = InferenceClient(SPACE_URL, token=HF_API_KEY)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
def fetch_response(prompt):
|
| 20 |
"""
|
| 21 |
Fetch full text response from the HF Inference Endpoint using the InferenceClient.
|
|
|
|
| 41 |
break
|
| 42 |
partial_text += response.token.text
|
| 43 |
yield response.token.text
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Streamlit Chat Interface
|
| 50 |
+
st.title("Chatbot Testing Interface")
|
| 51 |
+
|
| 52 |
+
# User Input Section
|
| 53 |
+
prompt = st.chat_input("Enter your message...")
|
| 54 |
+
|
| 55 |
+
if prompt:
|
| 56 |
+
# Display the user's message
|
| 57 |
+
st.chat_message("user").write(prompt)
|
| 58 |
+
|
| 59 |
+
# Build the chat history (use prompt directly for stateless behavior)
|
| 60 |
+
chat_history = f"<|user|>{prompt}<|end|> \n <|assistant|> "
|
| 61 |
+
|
| 62 |
+
# Generate the response
|
| 63 |
+
with st.spinner("Dubs is thinking... Woof Woof! 🐾"):
|
| 64 |
+
with st.chat_message("assistant", avatar=DUBS_PATH):
|
| 65 |
+
full_response = fetch_response(chat_history)
|
| 66 |
+
st.write_stream(full_response)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|