Kajise Org commited on
Commit
267551d
·
1 Parent(s): a197606

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from typing import Iterable
3
+
4
+ import gradio as Gradio
5
+ from gradio.themes.base import Base
6
+ from gradio.themes.utils import colors, fonts, sizes
7
+
8
+ from gpt4all import GPT4All
9
+ model = GPT4All("ggml-model-gpt4all-falcon-q4_0.bin")
10
+
11
+ theme = Gradio.themes.Monochrome(
12
+ primary_hue="purple",
13
+ secondary_hue="purple",
14
+ neutral_hue="neutral",
15
+ radius_size=Gradio.themes.sizes.radius_sm,
16
+ font=[Gradio.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
17
+ )
18
+
19
+ class PurpleTheme(Base):
20
+ def __init__(
21
+ self,
22
+ *,
23
+ primary_hue: colors.Color | str = colors.purple,
24
+ secondary_hue: colors.Color | str = colors.purple,
25
+ neutral_hue: colors.Color | str = colors.neutral,
26
+ spacing_size: sizes.Size | str = sizes.spacing_md,
27
+ radius_size: sizes.Size | str = sizes.radius_md,
28
+ font: fonts.Font
29
+ | str
30
+ | Iterable[fonts.Font | str] = (
31
+ fonts.GoogleFont("Inter"),
32
+ "ui-sans-serif",
33
+ "sans-serif",
34
+ ),
35
+ font_mono: fonts.Font
36
+ | str
37
+ | Iterable[fonts.Font | str] = (
38
+ fonts.GoogleFont("Space Grotesk"),
39
+ "ui-monospace",
40
+ "monospace",
41
+ ),
42
+ ):
43
+ super().__init__(
44
+ primary_hue=primary_hue,
45
+ secondary_hue=secondary_hue,
46
+ neutral_hue=neutral_hue,
47
+ spacing_size=spacing_size,
48
+ radius_size=radius_size,
49
+ font=font,
50
+ font_mono=font_mono,
51
+ )
52
+ super().set(
53
+ button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
54
+ button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
55
+ button_primary_text_color="white",
56
+ button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
57
+ block_shadow="*shadow_drop_lg",
58
+ button_shadow="*shadow_drop_lg",
59
+ input_background_fill="zinc",
60
+ input_border_color="*secondary_300",
61
+ input_shadow="*shadow_drop",
62
+ input_shadow_focus="*shadow_drop_lg",
63
+ )
64
+
65
+ custom_theme = PurpleTheme()
66
+
67
+ ins = '''### Instruction:
68
+ {}
69
+ ### Response:
70
+ '''
71
+
72
+ def run_falcon(input, scrape, scrape_type):
73
+ result = ""
74
+ for token in model.generate(ins.format(input), max_tokens=768, streaming=True):
75
+ print(token)
76
+ result += token
77
+ yield result
78
+
79
+ with Gradio.Blocks(theme=custom_theme, analytics_enabled=False, css=".generating {visibility: hidden}") as demo:
80
+ with Gradio.Column():
81
+ Gradio.Markdown(
82
+ """
83
+ ## GPT4ALL-Web
84
+ Uses falcon (q4_0)
85
+
86
+ *(added a little razzle dazzle aka web scraping, disabled in public revision)*
87
+
88
+ Type in the box below and click the button to generate answers to your most pressing questions!
89
+ """
90
+ )
91
+
92
+ with Gradio.Row():
93
+ with Gradio.Box():
94
+ instruction = Gradio.components.Textbox(placeholder="What does the Philippine flag represent?", label="Input", info="What things do you want to ask GPT4ALL?")
95
+ scraping = Gradio.Checkbox(value=False, label="Perform web scraping for unknown information", info="Scraping")
96
+ scrape_type = Gradio.Radio(["Web scraping", "Short descriptions"], label="Scraping tactic", info="Want GPT4ALL to utilize web scraping? If so—how thorough?")
97
+
98
+ with Gradio.Box():
99
+ output = Gradio.components.Textbox(value="", label="Output", info="GPT4ALL's thoughts")
100
+
101
+ submit = Gradio.Button("Generate", variant="primary")
102
+ submit.click(run_falcon, inputs=[instruction, scraping, scrape_type], outputs=[output])
103
+
104
+ demo.queue(concurrency_count=1).launch(debug=True) # type: ignore