Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,50 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 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 |
# import gradio as gr
|
| 50 |
# from langchain.llms import LlamaCpp
|
|
@@ -73,28 +73,3 @@
|
|
| 73 |
|
| 74 |
# iface = gr.Interface(fn=func, inputs="text", outputs="text")
|
| 75 |
# iface.launch()
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
import gradio as gr
|
| 79 |
-
from gpt4allj import Model
|
| 80 |
-
|
| 81 |
-
# Load the local model
|
| 82 |
-
model = Model('./ggml-gpt4all-j-v1.3-groovy.bin')
|
| 83 |
-
|
| 84 |
-
# Define a function that generates the model's response given a prompt
|
| 85 |
-
def generate_response(prompt):
|
| 86 |
-
response = model.generate(prompt)
|
| 87 |
-
return response
|
| 88 |
-
|
| 89 |
-
# Create a Gradio interface with a text input and an output text box
|
| 90 |
-
iface = gr.Interface(
|
| 91 |
-
fn=generate_response,
|
| 92 |
-
inputs="text",
|
| 93 |
-
outputs="text",
|
| 94 |
-
title="GPT-4 AllJ",
|
| 95 |
-
description="Generate responses using GPT-4 AllJ model."
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
# Run the Gradio interface
|
| 99 |
-
iface.launch()
|
| 100 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from langchain.llms import LlamaCpp
|
| 3 |
+
from langchain import PromptTemplate, LLMChain
|
| 4 |
+
from langchain.llms import GPT4All
|
| 5 |
+
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
| 6 |
|
| 7 |
|
| 8 |
+
# import requests
|
| 9 |
|
| 10 |
+
# url = "https://huggingface.co/TheBloke/Nous-Hermes-13B-GGML/resolve/main/nous-hermes-13b.ggmlv3.q4_0.bin"
|
| 11 |
|
| 12 |
+
# response = requests.get(url)
|
| 13 |
|
| 14 |
+
# with open("nous-hermes-13b.ggmlv3.q4_0.bin", "wb") as f:
|
| 15 |
+
# f.write(response.content)
|
| 16 |
|
| 17 |
|
| 18 |
+
print("DONE")
|
| 19 |
|
| 20 |
+
def func(user):
|
| 21 |
|
| 22 |
+
template = """
|
| 23 |
+
Your name is John and not a assistant but more like a chatbot. Respond precise not more words and act like a human. for example: user: How are you? You: I'm doing good how about you?. user: hello You: Hello how you doing?. Don't say How can I assist you today?.
|
| 24 |
+
Question: {question}
|
| 25 |
|
| 26 |
+
Answer: """
|
| 27 |
|
| 28 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 29 |
|
| 30 |
+
local_path = (
|
| 31 |
+
"./nous-hermes-13b.ggmlv3.q4_0.bin"
|
| 32 |
+
)
|
| 33 |
|
| 34 |
|
| 35 |
+
# # Callbacks support token-wise streaming
|
| 36 |
+
# callbacks = [StreamingStdOutCallbackHandler()]
|
| 37 |
|
| 38 |
+
# Verbose is required to pass to the callback manager
|
| 39 |
+
llm = LlamaCpp(model_path=".ggml-gpt4all-j-v1.3-groovy.bin")
|
| 40 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
| 41 |
+
question = user
|
| 42 |
+
llm_chain.run(question)
|
| 43 |
|
| 44 |
+
return llm_chain.run(question)
|
| 45 |
|
| 46 |
+
iface = gr.Interface(fn=func, inputs="text", outputs="text")
|
| 47 |
+
iface.launch()
|
| 48 |
|
| 49 |
# import gradio as gr
|
| 50 |
# from langchain.llms import LlamaCpp
|
|
|
|
| 73 |
|
| 74 |
# iface = gr.Interface(fn=func, inputs="text", outputs="text")
|
| 75 |
# iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|