File size: 1,247 Bytes
8acbf6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import streamlit as st
import json


model = st.selectbox('which model would you like to use',
                    ('MobileBERT', 'BERT', 'DeBERTa-v2'))


userInput = st.text_input(f"write to the {model}")

contextSelect = st.radio("Pick a context mode:", ["File", "Text"])
if contextSelect == "File":
    userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
    context = "/uploadfile"
else:
    userContext = st.text_input("write the context")
    context = "/contextText"

siteUrl = "http://127.0.0.1:8000"

if st.button("Envoyer la requête"):
    params = {'texte': userInput, "model": model}
    if userContext is not None:
        if contextSelect == "File":
            files = {"file": (userContext.name, userContext, userContext.type)}
            response = requests.post(
                siteUrl+context, params=params, files=files)
        else:
            params["context"] = userContext
            print(params)
            response = requests.post(siteUrl+context, params=params)
    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)