Spaces:
Sleeping
Sleeping
Commit
·
d60dac5
1
Parent(s):
f7105dc
initial commit
Browse files- .gitignore +1 -0
- __pycache__/utils.cpython-311.pyc +0 -0
- app.py +34 -0
- utils.py +18 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
__pycache__/utils.cpython-311.pyc
ADDED
|
Binary file (897 Bytes). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from utils import generate_text_embeddings
|
| 3 |
+
|
| 4 |
+
st.title("Echo Bot")
|
| 5 |
+
|
| 6 |
+
if "messages" not in st.session_state:
|
| 7 |
+
st.session_state.messages = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with st.sidebar :
|
| 11 |
+
st.markdown("# Inference Analytics")
|
| 12 |
+
st.markdown("---")
|
| 13 |
+
st.markdown("Tokens used :")
|
| 14 |
+
st.markdown("Average Querying Time :")
|
| 15 |
+
st.markdown("Average Inference Time :")
|
| 16 |
+
st.markdown("Cost Incurred :")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
for message in st.session_state.messages:
|
| 22 |
+
with st.chat_message(message["role"]):
|
| 23 |
+
st.markdown(message["content"])
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if prompt := st.chat_input("What is up?"):
|
| 27 |
+
query_embeddings = generate_text_embeddings(prompt)
|
| 28 |
+
st.chat_message("user").markdown(prompt)
|
| 29 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 30 |
+
|
| 31 |
+
response = f"Echo: {prompt}"
|
| 32 |
+
with st.chat_message("assistant"):
|
| 33 |
+
st.markdown(response)
|
| 34 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
utils.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
API_TOKEN = os.getenv('HF_TOKEN')
|
| 9 |
+
|
| 10 |
+
API_URL = "https://api-inference.huggingface.co/models/all-distilroberta-v1"
|
| 11 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 12 |
+
|
| 13 |
+
def generate_text_embeddings(texts):
|
| 14 |
+
model = SentenceTransformer('all-distilroberta-v1')
|
| 15 |
+
|
| 16 |
+
return model.encode(texts)
|
| 17 |
+
|
| 18 |
+
# Example usage:
|