LucasAguetai commited on
Commit
8acbf6e
1 Parent(s): 9f2a128

first push

Browse files
Files changed (6) hide show
  1. README.md +4 -4
  2. SM2.py +37 -0
  3. app.py +51 -0
  4. main.py +63 -0
  5. require.txt +4 -0
  6. requirements.txt +6 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: App
3
- emoji:
4
- colorFrom: gray
5
- colorTo: pink
6
  sdk: streamlit
7
  sdk_version: 1.32.2
8
  app_file: app.py
 
1
  ---
2
+ title: Streamlit
3
+ emoji: 🏃
4
+ colorFrom: yellow
5
+ colorTo: red
6
  sdk: streamlit
7
  sdk_version: 1.32.2
8
  app_file: app.py
SM2.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ import json
4
+
5
+
6
+ model = st.selectbox('which model would you like to use',
7
+ ('MobileBERT', 'BERT', 'DeBERTa-v2'))
8
+
9
+
10
+ userInput = st.text_input(f"write to the {model}")
11
+
12
+ contextSelect = st.radio("Pick a context mode:", ["File", "Text"])
13
+ if contextSelect == "File":
14
+ userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
15
+ context = "/uploadfile"
16
+ else:
17
+ userContext = st.text_input("write the context")
18
+ context = "/contextText"
19
+
20
+ siteUrl = "http://127.0.0.1:8000"
21
+
22
+ if st.button("Envoyer la requête"):
23
+ params = {'texte': userInput, "model": model}
24
+ if userContext is not None:
25
+ if contextSelect == "File":
26
+ files = {"file": (userContext.name, userContext, userContext.type)}
27
+ response = requests.post(
28
+ siteUrl+context, params=params, files=files)
29
+ else:
30
+ params["context"] = userContext
31
+ print(params)
32
+ response = requests.post(siteUrl+context, params=params)
33
+ else:
34
+ response = requests.post(siteUrl+'/withoutFile', params=params)
35
+
36
+ st.write("Statut de la requête:", response.status_code)
37
+ st.write("Réponse du serveur:", response.text)
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import streamlit as st
4
+
5
+ siteUrl = "http://127.0.0.1:8000"
6
+
7
+ userContext = None
8
+ context = None
9
+
10
+ with st.sidebar:
11
+ model = st.selectbox('which model would you like to use',
12
+ ('MobileBERT', 'BERT', 'DeBERTa-v2'))
13
+ contextSelect = st.radio("Pick a context mode:", ["File", "Text"])
14
+ if contextSelect == "File":
15
+ userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
16
+ context = "/uploadfile"
17
+ else:
18
+ userContext = st.text_input("write the context")
19
+ context = "/contextText"
20
+
21
+ st.title("ALOQAS")
22
+
23
+ """
24
+ bla bla bla
25
+ """
26
+
27
+ if "messages" not in st.session_state:
28
+ st.session_state["messages"] = [
29
+ {"role": "assistant", "content": "Hi, I'm ALOQAS. How can I help you?"}
30
+ ]
31
+
32
+ for msg in st.session_state.messages:
33
+ st.chat_message(msg["role"]).write(msg["content"])
34
+
35
+ if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
36
+ st.session_state.messages.append({"role": "user", "content": prompt})
37
+ st.chat_message("user").write(prompt)
38
+ params = {'texte': prompt, "model": model}
39
+ if userContext is not None:
40
+ if contextSelect == "File" and userContext:
41
+ # Préparation de la liste des fichiers pour l'envoi
42
+ files = [("file", (file.name, file, file.type)) for file in userContext]
43
+ response = requests.post(siteUrl + context, params=params, files=files)
44
+ else:
45
+ params["context"] = userContext
46
+ response = requests.post(siteUrl + context, params=params)
47
+ else:
48
+ response = requests.post(siteUrl + '/withoutFile', params=params)
49
+
50
+ st.write("Statut de la requête:", response.status_code)
51
+ st.write("Réponse du serveur:", response.text)
main.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException, File, UploadFile
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from typing import Annotated
4
+ import uvicorn
5
+ from fastapi import FastAPI, UploadFile, File
6
+ from typing import Union
7
+ import json
8
+ import csv
9
+
10
+
11
+ app = FastAPI()
12
+
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"],
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"],
19
+ )
20
+
21
+
22
+ @app.on_event("startup")
23
+ async def startup_event():
24
+ print("start")
25
+
26
+
27
+ @app.get("/")
28
+ async def root():
29
+ return {"message": "Hello World"}
30
+
31
+
32
+ @app.post("/uploadfile/")
33
+ async def create_upload_file(file: UploadFile, texte: str, model: str):
34
+
35
+ return {"model": model, "texte": texte, "filename": file.filename}
36
+
37
+
38
+ @app.post("/contextText/")
39
+ async def create_upload_file(context: str, texte: str, model: str):
40
+
41
+ return {"model": model, "texte": texte, "context": context}
42
+
43
+
44
+ @app.post("/withoutFile/")
45
+ async def create_upload_file(texte: str, model: str):
46
+
47
+ return {"model": model, "texte": texte}
48
+
49
+
50
+ def extract_data(file: UploadFile) -> Union[str, dict, list]:
51
+ if file.filename.endswith(".txt"):
52
+ data = file.file.read()
53
+ return data.decode("utf-8")
54
+ elif file.filename.endswith(".csv"):
55
+ data = file.file.read().decode("utf-8")
56
+ rows = data.split("\n")
57
+ reader = csv.DictReader(rows)
58
+ return [dict(row) for row in reader]
59
+ elif file.filename.endswith(".json"):
60
+ data = file.file.read().decode("utf-8")
61
+ return json.loads(data)
62
+ else:
63
+ return "Invalid file format"
require.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pip3 install python-multipart
2
+ pip3 install fastapi
3
+ pip3 install uvicorn
4
+ pip3 install fastapi.middleware.cors
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ python-multipart
4
+ fastapi
5
+ uvicorn
6
+ fastapi.middleware.cors