Descargando y probando el modelo
Browse files- .gitignore +5 -0
- app.py +44 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.gradio
|
2 |
+
bot
|
3 |
+
chat_bot_test.py
|
4 |
+
main.py
|
5 |
+
model
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import langchain_community,langchain
|
2 |
+
from langchain_community.llms import LlamaCpp
|
3 |
+
from langchain.schema import AIMessage, HumanMessage, SystemMessage
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
# Define the model path
|
7 |
+
model_path = "./model/Model-1.2B-Q8_0.gguf"
|
8 |
+
system_message = "You are a helpful assistant who acts like a pirate."
|
9 |
+
llm = LlamaCpp(
|
10 |
+
model_path=model_path,
|
11 |
+
temperature=0.8,
|
12 |
+
max_tokens=250,
|
13 |
+
top_p=0.6,
|
14 |
+
verbose=True
|
15 |
+
)
|
16 |
+
|
17 |
+
def stream_response(message, history):
|
18 |
+
print(f"Input: {message}. History: {history}\n")
|
19 |
+
|
20 |
+
history_langchain_format = []
|
21 |
+
history_langchain_format.append(SystemMessage(content=system_message))
|
22 |
+
|
23 |
+
for human, ai in history:
|
24 |
+
history_langchain_format.append(HumanMessage(content=human))
|
25 |
+
history_langchain_format.append(AIMessage(content=ai))
|
26 |
+
|
27 |
+
if message is not None:
|
28 |
+
history_langchain_format.append(HumanMessage(content=message))
|
29 |
+
partial_message = ""
|
30 |
+
for response in llm.stream(history_langchain_format):
|
31 |
+
partial_message += response
|
32 |
+
yield partial_message
|
33 |
+
|
34 |
+
|
35 |
+
demo_interface = gr.ChatInterface(
|
36 |
+
|
37 |
+
stream_response,
|
38 |
+
textbox=gr.Textbox(placeholder="Send to the LLM...",
|
39 |
+
container=False,
|
40 |
+
autoscroll=True,
|
41 |
+
scale=7),
|
42 |
+
)
|
43 |
+
|
44 |
+
demo_interface.launch(share=False, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
langchain-community==0.3.8
|
2 |
+
langchain==0.3.8
|
3 |
+
llama_cpp_python==0.3.2
|