Spaces:
Runtime error
Runtime error
ferferefer
commited on
Commit
•
cfb1176
1
Parent(s):
fdec595
- .gitattributes +37 -37
- README.md +13 -13
- app.py +86 -60
- db/{default__vector_store.jsonZone.Identifier → default__vector_store.json:Zone.Identifier} +0 -0
- db/{docstore.jsonZone.Identifier → docstore.json:Zone.Identifier} +0 -0
- db/{graph_store.jsonZone.Identifier → graph_store.json:Zone.Identifier} +0 -0
- db/{image__vector_store.jsonZone.Identifier → image__vector_store.json:Zone.Identifier} +0 -0
- db/{index_store.jsonZone.Identifier → index_store.json:Zone.Identifier} +0 -0
- requirements.txt +7 -4
.gitattributes
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
-
db/default__vector_store.json filter=lfs diff=lfs merge=lfs -text
|
37 |
-
db/docstore.json filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
db/default__vector_store.json filter=lfs diff=lfs merge=lfs -text
|
37 |
+
db/docstore.json filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
---
|
2 |
-
title: Marco O1
|
3 |
-
emoji: 💬
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: purple
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.7.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
short_description: 'Marco-O1 A model similar to OpenAI o1 can reason '
|
12 |
-
---
|
13 |
-
|
14 |
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
|
|
1 |
+
---
|
2 |
+
title: Marco O1
|
3 |
+
emoji: 💬
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.7.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: 'Marco-O1 A model similar to OpenAI o1 can reason '
|
12 |
+
---
|
13 |
+
|
14 |
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
app.py
CHANGED
@@ -1,61 +1,87 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
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 |
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from langchain.vectorstores import Chroma
|
4 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Load the embedding model
|
8 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
|
9 |
+
|
10 |
+
# Load the pre-existing vector database
|
11 |
+
persist_directory = "db"
|
12 |
+
vectordb = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
|
13 |
+
|
14 |
+
# Load the Marco-o1 model
|
15 |
+
pipe = pipeline("text-generation", model="AIDC-AI/Marco-o1", device_map="auto", torch_dtype="auto", trust_remote_code=True)
|
16 |
+
|
17 |
+
def get_relevant_context(query, k=3):
|
18 |
+
# Search the vector database for relevant documents
|
19 |
+
docs = vectordb.similarity_search(query, k=k)
|
20 |
+
# Combine the relevant documents into a single context string
|
21 |
+
context = "\n".join([doc.page_content for doc in docs])
|
22 |
+
return context
|
23 |
+
|
24 |
+
def respond(
|
25 |
+
message,
|
26 |
+
history: list[tuple[str, str]],
|
27 |
+
system_message,
|
28 |
+
max_tokens,
|
29 |
+
temperature,
|
30 |
+
top_p,
|
31 |
+
):
|
32 |
+
messages = [system_message]
|
33 |
+
|
34 |
+
# Get relevant context from the vector database
|
35 |
+
context = get_relevant_context(message)
|
36 |
+
|
37 |
+
# Add context to the system message
|
38 |
+
if context:
|
39 |
+
messages[0] = f"{system_message}\n\nRelevant context:\n{context}"
|
40 |
+
|
41 |
+
for val in history:
|
42 |
+
if val[0]:
|
43 |
+
messages.append(val[0])
|
44 |
+
if val[1]:
|
45 |
+
messages.append(val[1])
|
46 |
+
|
47 |
+
messages.append(message)
|
48 |
+
|
49 |
+
# Combine all messages into one string
|
50 |
+
input_text = "\n".join(messages)
|
51 |
+
|
52 |
+
response = pipe(
|
53 |
+
input_text,
|
54 |
+
max_length=max_tokens + len(input_text),
|
55 |
+
temperature=temperature,
|
56 |
+
top_p=top_p,
|
57 |
+
num_return_sequences=1
|
58 |
+
)[0]['generated_text']
|
59 |
+
|
60 |
+
# Extract new response
|
61 |
+
new_response = response[len(input_text):].strip()
|
62 |
+
|
63 |
+
yield new_response
|
64 |
+
|
65 |
+
demo = gr.ChatInterface(
|
66 |
+
respond,
|
67 |
+
additional_inputs=[
|
68 |
+
gr.Textbox(
|
69 |
+
value="You are a helpful AI assistant. Use the provided context to answer questions accurately.",
|
70 |
+
label="System message"
|
71 |
+
),
|
72 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
73 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
74 |
+
gr.Slider(
|
75 |
+
minimum=0.1,
|
76 |
+
maximum=1.0,
|
77 |
+
value=0.95,
|
78 |
+
step=0.05,
|
79 |
+
label="Top-p (nucleus sampling)",
|
80 |
+
),
|
81 |
+
],
|
82 |
+
title="Marco-O1 Assistant with Knowledge Base",
|
83 |
+
description="Ask questions about the documents in the knowledge base. The assistant will use the relevant context to provide accurate answers."
|
84 |
+
)
|
85 |
+
|
86 |
+
if __name__ == "__main__":
|
87 |
demo.launch()
|
db/{default__vector_store.jsonZone.Identifier → default__vector_store.json:Zone.Identifier}
RENAMED
File without changes
|
db/{docstore.jsonZone.Identifier → docstore.json:Zone.Identifier}
RENAMED
File without changes
|
db/{graph_store.jsonZone.Identifier → graph_store.json:Zone.Identifier}
RENAMED
File without changes
|
db/{image__vector_store.jsonZone.Identifier → image__vector_store.json:Zone.Identifier}
RENAMED
File without changes
|
db/{index_store.jsonZone.Identifier → index_store.json:Zone.Identifier}
RENAMED
File without changes
|
requirements.txt
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
-
torch
|
2 |
-
transformers
|
3 |
-
bitsandbytes
|
4 |
-
accelerate
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
bitsandbytes
|
4 |
+
accelerate
|
5 |
+
langchain
|
6 |
+
chromadb
|
7 |
+
sentence-transformers
|