Update app.py
Browse files
app.py
CHANGED
|
@@ -46,30 +46,55 @@
|
|
| 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
|
| 51 |
-
from langchain import PromptTemplate, LLMChain
|
| 52 |
-
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
| 53 |
|
| 54 |
-
print("DONE")
|
| 55 |
|
| 56 |
-
def func(user):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
return llm_chain.run(question)
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
iface.launch()
|
|
|
|
|
|
| 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
|
| 51 |
+
# from langchain import PromptTemplate, LLMChain
|
| 52 |
+
# from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
| 53 |
|
| 54 |
+
# print("DONE")
|
| 55 |
|
| 56 |
+
# def func(user):
|
| 57 |
+
# template = """
|
| 58 |
+
# 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?.
|
| 59 |
+
# Question: {question}
|
| 60 |
|
| 61 |
+
# Answer: """
|
| 62 |
|
| 63 |
+
# prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 64 |
|
| 65 |
+
# local_path = "./nous-hermes-13b.ggmlv3.q4_0.bin"
|
| 66 |
|
| 67 |
+
# llm = LlamaCpp(model_path=local_path)
|
| 68 |
+
# llm_chain = LLMChain(prompt=prompt, llm=llm, streaming=True) # Enable streaming mode
|
| 69 |
+
# question = user
|
| 70 |
+
# llm_chain.run(question)
|
| 71 |
+
|
| 72 |
+
# return llm_chain.run(question)
|
| 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.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 |
+
|