Spaces:
Running
Running
test
Browse files
app.py
CHANGED
@@ -1,16 +1,135 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
from llama_cpp import Llama
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
|
5 |
hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
|
6 |
-
|
7 |
llm = Llama(model_path="./ggjt-model.bin", n_threads=2)
|
8 |
|
9 |
-
def chat(input):
|
10 |
-
resp = llm(input)
|
11 |
-
return resp['choices'][0]['text']
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
g.queue(concurrency_count=1)
|
16 |
-
g.launch()
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
from typing import Iterable
|
3 |
import gradio as gr
|
4 |
+
from gradio.themes.base import Base
|
5 |
+
from gradio.themes.utils import colors, fonts, sizes
|
6 |
+
|
7 |
from llama_cpp import Llama
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
|
10 |
hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
|
|
|
11 |
llm = Llama(model_path="./ggjt-model.bin", n_threads=2)
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
+
ins = '''### Instruction:
|
15 |
+
{}
|
16 |
+
### Response:
|
17 |
+
'''
|
18 |
+
|
19 |
+
theme = gr.themes.Monochrome(
|
20 |
+
primary_hue="indigo",
|
21 |
+
secondary_hue="blue",
|
22 |
+
neutral_hue="slate",
|
23 |
+
radius_size=gr.themes.sizes.radius_sm,
|
24 |
+
font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
|
25 |
+
)
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
def generate(instruction):
|
31 |
+
response = resp = llm(ins.format(instruction))
|
32 |
+
result = ""
|
33 |
+
for word in response.split(" "):
|
34 |
+
result += word + " "
|
35 |
+
yield result
|
36 |
+
|
37 |
+
examples = [
|
38 |
+
"Instead of making a peanut butter and jelly sandwich, what else could I combine peanut butter with in a sandwich? Give five ideas",
|
39 |
+
"How do I make a campfire?",
|
40 |
+
"Explain to me the difference between nuclear fission and fusion.",
|
41 |
+
"I'm selling my Nikon D-750, write a short blurb for my ad."
|
42 |
+
]
|
43 |
+
|
44 |
+
def process_example(args):
|
45 |
+
for x in generate(args):
|
46 |
+
pass
|
47 |
+
return x
|
48 |
+
|
49 |
+
css = ".generating {visibility: hidden}"
|
50 |
+
|
51 |
+
# Based on the gradio theming guide and borrowed from https://huggingface.co/spaces/shivi/dolly-v2-demo
|
52 |
+
class SeafoamCustom(Base):
|
53 |
+
def __init__(
|
54 |
+
self,
|
55 |
+
*,
|
56 |
+
primary_hue: colors.Color | str = colors.emerald,
|
57 |
+
secondary_hue: colors.Color | str = colors.blue,
|
58 |
+
neutral_hue: colors.Color | str = colors.blue,
|
59 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
60 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
61 |
+
font: fonts.Font
|
62 |
+
| str
|
63 |
+
| Iterable[fonts.Font | str] = (
|
64 |
+
fonts.GoogleFont("Quicksand"),
|
65 |
+
"ui-sans-serif",
|
66 |
+
"sans-serif",
|
67 |
+
),
|
68 |
+
font_mono: fonts.Font
|
69 |
+
| str
|
70 |
+
| Iterable[fonts.Font | str] = (
|
71 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
72 |
+
"ui-monospace",
|
73 |
+
"monospace",
|
74 |
+
),
|
75 |
+
):
|
76 |
+
super().__init__(
|
77 |
+
primary_hue=primary_hue,
|
78 |
+
secondary_hue=secondary_hue,
|
79 |
+
neutral_hue=neutral_hue,
|
80 |
+
spacing_size=spacing_size,
|
81 |
+
radius_size=radius_size,
|
82 |
+
font=font,
|
83 |
+
font_mono=font_mono,
|
84 |
+
)
|
85 |
+
super().set(
|
86 |
+
button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
|
87 |
+
button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
|
88 |
+
button_primary_text_color="white",
|
89 |
+
button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
|
90 |
+
block_shadow="*shadow_drop_lg",
|
91 |
+
button_shadow="*shadow_drop_lg",
|
92 |
+
input_background_fill="zinc",
|
93 |
+
input_border_color="*secondary_300",
|
94 |
+
input_shadow="*shadow_drop",
|
95 |
+
input_shadow_focus="*shadow_drop_lg",
|
96 |
+
)
|
97 |
+
|
98 |
+
|
99 |
+
seafoam = SeafoamCustom()
|
100 |
+
|
101 |
+
|
102 |
+
with gr.Blocks(theme=seafoam, analytics_enabled=False, css=css) as demo:
|
103 |
+
with gr.Column():
|
104 |
+
gr.Markdown(
|
105 |
+
""" ## GPT4ALL
|
106 |
+
|
107 |
+
An ecosystem of open-source chatbots trained on a massive collections of clean assistant data including code, stories and dialogue
|
108 |
+
|
109 |
+
Type in the box below and click the button to generate answers to your most pressing questions!
|
110 |
+
|
111 |
+
"""
|
112 |
+
)
|
113 |
+
|
114 |
+
with gr.Row():
|
115 |
+
with gr.Column(scale=3):
|
116 |
+
instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
|
117 |
+
|
118 |
+
with gr.Box():
|
119 |
+
gr.Markdown("**Answer**")
|
120 |
+
output = gr.Markdown(elem_id="q-output")
|
121 |
+
submit = gr.Button("Generate", variant="primary")
|
122 |
+
gr.Examples(
|
123 |
+
examples=examples,
|
124 |
+
inputs=[instruction],
|
125 |
+
cache_examples=True,
|
126 |
+
fn=process_example,
|
127 |
+
outputs=[output],
|
128 |
+
)
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
submit.click(generate, inputs=[instruction], outputs=[output])
|
133 |
+
instruction.submit(generate, inputs=[instruction], outputs=[output])
|
134 |
|
135 |
+
demo.queue(concurrency_count=1).launch(debug=True)
|
|
|
|