Dagfinn1962 commited on
Commit
71daf4d
1 Parent(s): 6e9e23f

Update app.py

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