Spaces:
Sleeping
Sleeping
update
Browse files- .gitignore +2 -0
- app.py +11 -23
- models/ggml-gpt4all-l13b-snoozy.bin +0 -3
.gitignore
CHANGED
@@ -1 +1,3 @@
|
|
|
|
|
|
1 |
models/ggml-gpt4all-l13b-snoozy.bin
|
|
|
1 |
+
.env
|
2 |
+
_app.py
|
3 |
models/ggml-gpt4all-l13b-snoozy.bin
|
app.py
CHANGED
@@ -2,36 +2,24 @@ from langchain import PromptTemplate, LLMChain
|
|
2 |
from langchain.llms import GPT4All
|
3 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
4 |
import gradio as gr
|
5 |
-
import
|
6 |
-
from
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
template = """Question: {question}
|
10 |
|
|
|
|
|
11 |
Answer: Let's think step by step."""
|
12 |
|
13 |
prompt = PromptTemplate(template=template, input_variables=["question"])
|
14 |
-
|
15 |
-
local_path = './models/ggml-gpt4all-l13b-snoozy.bin' # replace with your desired local file path
|
16 |
-
Path(local_path).parent.mkdir(parents=True, exist_ok=True)
|
17 |
-
|
18 |
-
# Example model. Check https://github.com/nomic-ai/pygpt4all for the latest models.
|
19 |
-
url = 'http://gpt4all.io/models/ggml-gpt4all-l13b-snoozy.bin'
|
20 |
-
|
21 |
-
# send a GET request to the URL to download the file. Stream since it's large
|
22 |
-
response = requests.get(url, stream=True)
|
23 |
-
|
24 |
-
# open the file in binary mode and write the contents of the response to it in chunks
|
25 |
-
# This is a large file, so be prepared to wait.
|
26 |
-
with open(local_path, 'wb') as f:
|
27 |
-
for chunk in tqdm(response.iter_content(chunk_size=8192)):
|
28 |
-
if chunk:
|
29 |
-
f.write(chunk)
|
30 |
-
|
31 |
# Callbacks support token-wise streaming
|
32 |
callbacks = [StreamingStdOutCallbackHandler()]
|
33 |
# Verbose is required to pass to the callback manager
|
34 |
-
llm = GPT4All(model=
|
35 |
|
36 |
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
37 |
|
@@ -43,7 +31,7 @@ def chatbot_interface(input_text):
|
|
43 |
# Define the Gradio app
|
44 |
gradio_app = gr.Interface(
|
45 |
fn=chatbot_interface,
|
46 |
-
inputs=gr.inputs.Textbox(
|
47 |
outputs=gr.outputs.Textbox(),
|
48 |
title="ConversationChain Chatbot",
|
49 |
description="A chatbot interface powered by ConversationChain and Hugging Face.",
|
|
|
2 |
from langchain.llms import GPT4All
|
3 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
4 |
import gradio as gr
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
+
|
8 |
+
model_path = hf_hub_download(repo_id="microsoft/DialoGPT-medium", filename="tf_model.h5")
|
9 |
+
# Load the tokenizer and model
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
12 |
|
|
|
13 |
|
14 |
+
template = """Question: {question}
|
15 |
+
------------------
|
16 |
Answer: Let's think step by step."""
|
17 |
|
18 |
prompt = PromptTemplate(template=template, input_variables=["question"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Callbacks support token-wise streaming
|
20 |
callbacks = [StreamingStdOutCallbackHandler()]
|
21 |
# Verbose is required to pass to the callback manager
|
22 |
+
llm = GPT4All(model=model, callbacks=callbacks, verbose=True)
|
23 |
|
24 |
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
25 |
|
|
|
31 |
# Define the Gradio app
|
32 |
gradio_app = gr.Interface(
|
33 |
fn=chatbot_interface,
|
34 |
+
inputs=gr.inputs.Textbox(label="Say something..."),
|
35 |
outputs=gr.outputs.Textbox(),
|
36 |
title="ConversationChain Chatbot",
|
37 |
description="A chatbot interface powered by ConversationChain and Hugging Face.",
|
models/ggml-gpt4all-l13b-snoozy.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:a7237cc5ddb014293c485c9c5effa91684693ef230ec267b0b100bf699bc97a5
|
3 |
-
size 184352768
|
|
|
|
|
|
|
|