ferferefer commited on
Commit
cfb1176
1 Parent(s): fdec595
.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
- # Загрузка модели Marco-o1 с квантизацией
5
- pipe = pipeline("text-generation", model="AIDC-AI/Marco-o1", device_map="auto", torch_dtype="auto", trust_remote_code=True)
6
-
7
- def respond(
8
- message,
9
- history: list[tuple[str, str]],
10
- system_message,
11
- max_tokens,
12
- temperature,
13
- top_p,
14
- ):
15
- messages = [system_message]
16
-
17
- for val in history:
18
- if val[0]:
19
- messages.append(val[0])
20
- if val[1]:
21
- messages.append(val[1])
22
-
23
- messages.append(message)
24
-
25
- # Объединяем все сообщения в одну строку для передачи в модель
26
- input_text = "\n".join(messages)
27
-
28
- response = pipe(
29
- input_text,
30
- max_length=max_tokens + len(input_text),
31
- temperature=temperature,
32
- top_p=top_p,
33
- num_return_sequences=1
34
- )[0]['generated_text']
35
-
36
- # Извлекаем новый ответ, исключая входные сообщения
37
- new_response = response[len(input_text):].strip()
38
-
39
- yield new_response
40
-
41
- """
42
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
43
- """
44
- demo = gr.ChatInterface(
45
- respond,
46
- additional_inputs=[
47
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
48
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
49
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
50
- gr.Slider(
51
- minimum=0.1,
52
- maximum=1.0,
53
- value=0.95,
54
- step=0.05,
55
- label="Top-p (nucleus sampling)",
56
- ),
57
- ],
58
- )
59
-
60
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.jsonZone.Identifier → default__vector_store.json:Zone.Identifier} RENAMED
File without changes
db/{docstore.jsonZone.Identifier → docstore.json:Zone.Identifier} RENAMED
File without changes
db/{graph_store.jsonZone.Identifier → graph_store.json:Zone.Identifier} RENAMED
File without changes
db/{image__vector_store.jsonZone.Identifier → image__vector_store.json:Zone.Identifier} RENAMED
File without changes
db/{index_store.jsonZone.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