Spaces:
Sleeping
Sleeping
File size: 2,650 Bytes
c1c4977 24d620f b6e1d0d 9e80ceb d943ab1 24d620f 9e80ceb d943ab1 e7169f6 d943ab1 52ef193 d943ab1 c9b44c4 d943ab1 100673e d943ab1 82909b4 100673e d943ab1 100673e d943ab1 ca90665 82909b4 819658d 82909b4 c9b44c4 d943ab1 2249329 a7a6cbd 634e250 187d5dc 634e250 30f53de a7a6cbd 634e250 30f53de 52ef193 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | import os
import streamlit as st
from datasets import load_dataset
from huggingface_hub import InferenceClient
# Get the API key from the environment variable
api_key = os.getenv("HF_API_KEY")
client = InferenceClient(api_key=api_key)
# Load the dataset
dataset = load_dataset("andreska/adregadocs", split="test")
# Function to read the content from the dataset
def read_dataset(dataset):
text = []
for item in dataset:
text.append(item['text'])
return "\n".join(text)
context = read_dataset(dataset)
# Inject custom CSS to change the background color to yellow
st.markdown(
"""
<style>
.scrollable-div {
max-height: 300px;
overflow-y: auto;
padding: 10px;
border: 1px solid #ccc;
background-color: #f9f9f9; }
</style>
""",
unsafe_allow_html=True
)
def handle_submit():
user_input = st.session_state.user_input
st.session_state.user_input = ""
if user_input:
if st.session_state.include_context:
messages = [
{"role": "system", "content": f"Context: {context}"},
{"role": "user", "content": user_input}
]
else:
messages = [
{"role": "system", "content": f"Context: Adrega is a powerful project management and reporting tool. It can show Gantt diagrams, S-Curves, Tabular reports and various charts in single reports, report bundles or in a customizable dashboard."},
{"role": "user", "content": user_input}
]
completion = client.chat.completions.create(
#model="Qwen/Qwen2.5-72B-Instruct",
#model="Qwen/Qwen2.5-Coder-32B-Instruct",
model="HuggingFaceTB/SmolLM2-1.7B-Instruct",
messages=messages,
max_tokens=1000
)
answer = completion.choices[0].message['content']
st.session_state.conversation = f"<p><strong>User:</strong> {user_input}</p><p><strong>Adrega AI:</strong> {answer}</p>" + st.session_state.conversation
else:
st.session_state.conversation(f"<p><strong>Adrega AI:</strong>: Please enter a question.")
#st.title("Adrega AI Help")
st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
col1, col2 = st.columns(2)
with col1:
if st.button("Ask"):
handle_submit()
if 'conversation' not in st.session_state:
st.session_state.conversation = ""
with col2:
st.session_state.include_context = st.checkbox('Search in Help')
st.markdown(f'<div class="scrollable-div">{st.session_state.conversation}</div>', unsafe_allow_html=True)
|