Spaces:
Runtime error
Runtime error
Kajise Org
commited on
Commit
•
0b3dcc4
1
Parent(s):
3bf96ec
Update app.py
Browse files
app.py
CHANGED
@@ -22,15 +22,15 @@ from bs4 import BeautifulSoup
|
|
22 |
from SearchResult import SearchResult
|
23 |
|
24 |
headers = {
|
25 |
-
|
26 |
}
|
27 |
|
28 |
theme = gr.themes.Monochrome(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
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 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
90 |
examples = [
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
]
|
96 |
|
97 |
def process_example(args):
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
css = ".generating {visibility: hidden}"
|
103 |
|
104 |
class PurpleTheme(Base):
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
|
151 |
custom_theme = PurpleTheme()
|
152 |
|
153 |
with gr.Blocks(theme=custom_theme, analytics_enabled=False, css=css) as demo:
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
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)
|