Kajise Org commited on
Commit
0b3dcc4
1 Parent(s): 3bf96ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -96
app.py CHANGED
@@ -22,15 +22,15 @@ from bs4 import BeautifulSoup
22
  from SearchResult import SearchResult
23
 
24
  headers = {
25
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
26
  }
27
 
28
  theme = gr.themes.Monochrome(
29
- primary_hue="purple",
30
- secondary_hue="red",
31
- neutral_hue="neutral",
32
- radius_size=gr.themes.sizes.radius_sm,
33
- font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
34
  )
35
 
36
  def search_ddg(question: str):
@@ -76,111 +76,110 @@ def gather_data(search: str):
76
  text_content += data.text_content + "\n\n"
77
  else:
78
  text_content += ""
79
-
80
- return text_content
81
 
82
  def generate(instruction):
83
- base_prompt = ins.format(instruction)
84
- gathered_data = gather_data(instruction)
85
 
86
- response = llm(ins.format(base_prompt + "\n" + gathered_data))
87
- result = response['choices'][0]['text']
88
- return result
89
 
90
  examples = [
91
- "How do dogs bark?",
92
- "Why are apples red?",
93
- "How do I make a campfire?",
94
- "Why do cats love to chirp at something?"
95
  ]
96
 
97
  def process_example(args):
98
- for x in generate(args):
99
- pass
100
- return x
101
-
102
  css = ".generating {visibility: hidden}"
103
 
104
  class PurpleTheme(Base):
105
- def __init__(
106
- self,
107
- *,
108
- primary_hue: colors.Color | str = colors.purple,
109
- secondary_hue: colors.Color | str = colors.red,
110
- neutral_hue: colors.Color | str = colors.neutral,
111
- spacing_size: sizes.Size | str = sizes.spacing_md,
112
- radius_size: sizes.Size | str = sizes.radius_md,
113
- font: fonts.Font
114
- | str
115
- | Iterable[fonts.Font | str] = (
116
- fonts.GoogleFont("Inter"),
117
- "ui-sans-serif",
118
- "sans-serif",
119
- ),
120
- font_mono: fonts.Font
121
- | str
122
- | Iterable[fonts.Font | str] = (
123
- fonts.GoogleFont("Space Grotesk"),
124
- "ui-monospace",
125
- "monospace",
126
- ),
127
- ):
128
- super().__init__(
129
- primary_hue=primary_hue,
130
- secondary_hue=secondary_hue,
131
- neutral_hue=neutral_hue,
132
- spacing_size=spacing_size,
133
- radius_size=radius_size,
134
- font=font,
135
- font_mono=font_mono,
136
- )
137
- super().set(
138
- button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
139
- button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
140
- button_primary_text_color="white",
141
- button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
142
- block_shadow="*shadow_drop_lg",
143
- button_shadow="*shadow_drop_lg",
144
- input_background_fill="zinc",
145
- input_border_color="*secondary_300",
146
- input_shadow="*shadow_drop",
147
- input_shadow_focus="*shadow_drop_lg",
148
- )
149
 
150
 
151
  custom_theme = PurpleTheme()
152
 
153
  with gr.Blocks(theme=custom_theme, analytics_enabled=False, css=css) as demo:
154
- with gr.Column():
155
- gr.Markdown(
156
- """ ## GPT4ALL
157
-
158
- 7b quantized 4bit (q4_0)
159
-
160
- Type in the box below and click the button to generate answers to your most pressing questions!
161
-
162
- """
163
- )
164
-
165
- with gr.Row():
166
- with gr.Column(scale=3):
167
- instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
168
-
169
- with gr.Box():
170
- gr.Markdown("**Answer**")
171
- output = gr.Markdown(elem_id="q-output")
172
- submit = gr.Button("Generate", variant="primary")
173
- gr.Examples(
174
- examples=examples,
175
- inputs=[instruction],
176
- cache_examples=False,
177
- fn=process_example,
178
- outputs=[output],
179
- )
180
-
181
-
182
-
183
- submit.click(generate, inputs=[instruction], outputs=[output])
184
- instruction.submit(generate, inputs=[instruction], outputs=[output])
185
 
186
  demo.queue(concurrency_count=1).launch(debug=True)
 
22
  from SearchResult import SearchResult
23
 
24
  headers = {
25
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
26
  }
27
 
28
  theme = gr.themes.Monochrome(
29
+ primary_hue="purple",
30
+ secondary_hue="red",
31
+ neutral_hue="neutral",
32
+ radius_size=gr.themes.sizes.radius_sm,
33
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
34
  )
35
 
36
  def search_ddg(question: str):
 
76
  text_content += data.text_content + "\n\n"
77
  else:
78
  text_content += ""
79
+ return text_content
 
80
 
81
  def generate(instruction):
82
+ base_prompt = ins.format(instruction)
83
+ gathered_data = gather_data(instruction)
84
 
85
+ response = llm(ins.format(base_prompt + "\n" + gathered_data))
86
+ result = response['choices'][0]['text']
87
+ return result
88
 
89
  examples = [
90
+ "How do dogs bark?",
91
+ "Why are apples red?",
92
+ "How do I make a campfire?",
93
+ "Why do cats love to chirp at something?"
94
  ]
95
 
96
  def process_example(args):
97
+ for x in generate(args):
98
+ pass
99
+ return x
100
+
101
  css = ".generating {visibility: hidden}"
102
 
103
  class PurpleTheme(Base):
104
+ def __init__(
105
+ self,
106
+ *,
107
+ primary_hue: colors.Color | str = colors.purple,
108
+ secondary_hue: colors.Color | str = colors.red,
109
+ neutral_hue: colors.Color | str = colors.neutral,
110
+ spacing_size: sizes.Size | str = sizes.spacing_md,
111
+ radius_size: sizes.Size | str = sizes.radius_md,
112
+ font: fonts.Font
113
+ | str
114
+ | Iterable[fonts.Font | str] = (
115
+ fonts.GoogleFont("Inter"),
116
+ "ui-sans-serif",
117
+ "sans-serif",
118
+ ),
119
+ font_mono: fonts.Font
120
+ | str
121
+ | Iterable[fonts.Font | str] = (
122
+ fonts.GoogleFont("Space Grotesk"),
123
+ "ui-monospace",
124
+ "monospace",
125
+ ),
126
+ ):
127
+ super().__init__(
128
+ primary_hue=primary_hue,
129
+ secondary_hue=secondary_hue,
130
+ neutral_hue=neutral_hue,
131
+ spacing_size=spacing_size,
132
+ radius_size=radius_size,
133
+ font=font,
134
+ font_mono=font_mono,
135
+ )
136
+ super().set(
137
+ button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
138
+ button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
139
+ button_primary_text_color="white",
140
+ button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
141
+ block_shadow="*shadow_drop_lg",
142
+ button_shadow="*shadow_drop_lg",
143
+ input_background_fill="zinc",
144
+ input_border_color="*secondary_300",
145
+ input_shadow="*shadow_drop",
146
+ input_shadow_focus="*shadow_drop_lg",
147
+ )
148
 
149
 
150
  custom_theme = PurpleTheme()
151
 
152
  with gr.Blocks(theme=custom_theme, analytics_enabled=False, css=css) as demo:
153
+ with gr.Column():
154
+ gr.Markdown(
155
+ """ ## GPT4ALL
156
+
157
+ 7b quantized 4bit (q4_0)
158
+
159
+ Type in the box below and click the button to generate answers to your most pressing questions!
160
+
161
+ """
162
+ )
163
+
164
+ with gr.Row():
165
+ with gr.Column(scale=3):
166
+ instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
167
+
168
+ with gr.Box():
169
+ gr.Markdown("**Answer**")
170
+ output = gr.Markdown(elem_id="q-output")
171
+ submit = gr.Button("Generate", variant="primary")
172
+ gr.Examples(
173
+ examples=examples,
174
+ inputs=[instruction],
175
+ cache_examples=False,
176
+ fn=process_example,
177
+ outputs=[output],
178
+ )
179
+
180
+
181
+
182
+ submit.click(generate, inputs=[instruction], outputs=[output])
183
+ instruction.submit(generate, inputs=[instruction], outputs=[output])
184
 
185
  demo.queue(concurrency_count=1).launch(debug=True)