File size: 2,303 Bytes
8acbf6e
 
 
5b4d076
8acbf6e
28ac775
8acbf6e
 
 
 
 
d92c6ee
 
73a1a59
e09ff79
8acbf6e
 
3b808f0
8acbf6e
cf69571
3b808f0
8acbf6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b4d076
 
 
 
 
8acbf6e
3b808f0
8acbf6e
5b4d076
 
d92c6ee
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import streamlit as st
import json

siteUrl = "https://aloqas-aloqas-qa-fastapi.hf.space"

userContext = None
context = None

with st.sidebar:
    st.title("Configuration")
    model = st.selectbox('Which model would you like to use?',
                         ('SqueezeBERT', 'BERT', 'DeBERTa-v2'))
    contextSelect = st.radio("Pick a context mode:", ["Text", "File"])
    if contextSelect == "File":
        userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
        context = "/uploadfile/"
    else:
        userContext = st.text_area("write the context")
        context = "/contextText/"

st.title("ALOQAS")

"""
bla bla bla
"""

if "messages" not in st.session_state:
    st.session_state["messages"] = [
        {"role": "assistant", "content": "Hi, I'm ALOQAS. How can I help you?"}
    ]

if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
    st.session_state.messages.append({"role": "user", "content": prompt})
    params = {'texte': prompt, "model": model}
    if userContext is not None:
        if contextSelect == "File" and userContext:
            # Préparation de la liste des fichiers pour l'envoi
            files = [("file", (file.name, file, file.type)) for file in userContext]
            response = requests.post(siteUrl + context, params=params, files=files)
        else:
            params["context"] = userContext
            request_url = f"{siteUrl}/{model.lower()}/?context={userContext}&question={prompt}"
            response = requests.post(request_url)
            print(response.text)
            st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text)["answer"]})

    else:
        response = requests.post(siteUrl + '/withoutFile/', params=params)

    # st.write("Statut de la requête:", response.status_code)
    # st.write("Réponse du serveur:", response.text)

    with st.sidebar:
        st.title("Statistics on the last answer")
        st.write(f"Score: {round(json.loads(response.text)["score"], 3)}")
        st.write(f"Start: {json.loads(response.text)["start"]}")
        st.write(f"End: {json.loads(response.text)["end"]}")

for msg in st.session_state.messages:
    st.chat_message(msg["role"]).write(msg["content"])