Spaces:
Sleeping
Sleeping
Denis PEYRUSAUBES commited on
Commit ·
2e1f08c
1
Parent(s): 030e182
ok
Browse files- ChatMixtral.py +22 -0
- __pycache__/ChatMixtral.cpython-310.pyc +0 -0
- __pycache__/rag.cpython-310.pyc +0 -0
- app.py +4 -4
- requirements.txt +4 -1
ChatMixtral.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
|
| 4 |
+
class ChatMixtral:
|
| 5 |
+
|
| 6 |
+
def __init__(self):
|
| 7 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 8 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_id, device_map="auto", load_in_4bit=True
|
| 10 |
+
)
|
| 11 |
+
self.tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1", padding_side="left")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def ask(self, query: str):
|
| 15 |
+
model_inputs = self.tokenizer(["A list of colors: red, blue"], return_tensors="pt").to("cuda")
|
| 16 |
+
generated_ids = self.model.generate(**model_inputs)
|
| 17 |
+
return self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def clear(self):
|
| 22 |
+
printf("cleaning")
|
__pycache__/ChatMixtral.cpython-310.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
__pycache__/rag.cpython-310.pyc
ADDED
|
Binary file (2.81 kB). View file
|
|
|
app.py
CHANGED
|
@@ -2,9 +2,9 @@ import os
|
|
| 2 |
import tempfile
|
| 3 |
import streamlit as st
|
| 4 |
from streamlit_chat import message
|
| 5 |
-
from
|
| 6 |
|
| 7 |
-
st.set_page_config(page_title="
|
| 8 |
|
| 9 |
|
| 10 |
def display_messages():
|
|
@@ -42,9 +42,9 @@ def read_and_save_file():
|
|
| 42 |
def page():
|
| 43 |
if len(st.session_state) == 0:
|
| 44 |
st.session_state["messages"] = []
|
| 45 |
-
st.session_state["assistant"] =
|
| 46 |
|
| 47 |
-
st.header("
|
| 48 |
|
| 49 |
st.subheader("Upload a document")
|
| 50 |
st.file_uploader(
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import streamlit as st
|
| 4 |
from streamlit_chat import message
|
| 5 |
+
from ChatMixtral import ChatMixtral
|
| 6 |
|
| 7 |
+
st.set_page_config(page_title="ChatMixtral")
|
| 8 |
|
| 9 |
|
| 10 |
def display_messages():
|
|
|
|
| 42 |
def page():
|
| 43 |
if len(st.session_state) == 0:
|
| 44 |
st.session_state["messages"] = []
|
| 45 |
+
st.session_state["assistant"] = ChatMixtral()
|
| 46 |
|
| 47 |
+
st.header("ChatMixtral")
|
| 48 |
|
| 49 |
st.subheader("Upload a document")
|
| 50 |
st.file_uploader(
|
requirements.txt
CHANGED
|
@@ -3,4 +3,7 @@ streamlit==1.31.0
|
|
| 3 |
streamlit-chat==0.1.1
|
| 4 |
pypdf==4.0.1
|
| 5 |
chromadb==0.4.22
|
| 6 |
-
fastembed==0.1.3
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
streamlit-chat==0.1.1
|
| 4 |
pypdf==4.0.1
|
| 5 |
chromadb==0.4.22
|
| 6 |
+
fastembed==0.1.3
|
| 7 |
+
torch
|
| 8 |
+
transformers
|
| 9 |
+
accelerate
|