Spaces:
Runtime error
Runtime error
Initial commit
Browse files- README.md +6 -9
- app.py +122 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
title: dolphin-2_6-phi-2-GGUF
|
2 |
+
emoji: 𓄿
|
3 |
+
colorFrom: purple
|
4 |
+
colorTo: blue
|
|
|
5 |
sdk: gradio
|
6 |
+
sdk_version: 3.33.1
|
7 |
app_file: app.py
|
8 |
pinned: false
|
9 |
+
license: openrail
|
|
|
|
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="TheBloke/dolphin-2_6-phi-2-GGUF", filename="dolphin-2_6-phi-2.Q5_K_S.gguf", local_dir=".")
|
11 |
+
llm = Llama(model_path="./dolphin-2_6-phi-2.Q5_K_S.gguf")
|
12 |
+
|
13 |
+
ins = '''<|im_start|>user
|
14 |
+
{question}<|im_end|>
|
15 |
+
<|im_start|>assistant
|
16 |
+
'''
|
17 |
+
|
18 |
+
theme = gr.themes.Monochrome(
|
19 |
+
primary_hue="purple",
|
20 |
+
secondary_hue="blue",
|
21 |
+
neutral_hue="neutral",
|
22 |
+
radius_size=gr.themes.sizes.radius_sm,
|
23 |
+
font=[gr.themes.GoogleFont("Space Grotesk"), "ui-sans-serif", "system-ui", "sans-serif"],
|
24 |
+
)
|
25 |
+
|
26 |
+
def generate(instruction):
|
27 |
+
prompt = ins.format(question=instruction)
|
28 |
+
response = llm(prompt, stop=['<|im_start|>user', '<|im_end|>'])
|
29 |
+
result = response['choices'][0]['text']
|
30 |
+
return result
|
31 |
+
|
32 |
+
examples = [
|
33 |
+
"How do dogs bark?",
|
34 |
+
"Why are apples red?",
|
35 |
+
"How do I make a campfire?",
|
36 |
+
"Why do cats love to chirp at something?"
|
37 |
+
]
|
38 |
+
|
39 |
+
def process_example(args):
|
40 |
+
for x in generate(args):
|
41 |
+
pass
|
42 |
+
return x
|
43 |
+
|
44 |
+
css = ".generating {visibility: hidden}"
|
45 |
+
|
46 |
+
class BlueTheme(Base):
|
47 |
+
def __init__(
|
48 |
+
self,
|
49 |
+
*,
|
50 |
+
primary_hue: colors.Color | str = colors.purple,
|
51 |
+
secondary_hue: colors.Color | str = colors.blue,
|
52 |
+
neutral_hue: colors.Color | str = colors.neutral,
|
53 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
54 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
55 |
+
font: fonts.Font
|
56 |
+
| str
|
57 |
+
| Iterable[fonts.Font | str] = (
|
58 |
+
fonts.GoogleFont("Space Grotesk"),
|
59 |
+
"ui-sans-serif",
|
60 |
+
"sans-serif",
|
61 |
+
),
|
62 |
+
font_mono: fonts.Font
|
63 |
+
| str
|
64 |
+
| Iterable[fonts.Font | str] = (
|
65 |
+
fonts.GoogleFont("Space Mono"),
|
66 |
+
"ui-monospace",
|
67 |
+
"monospace",
|
68 |
+
),
|
69 |
+
):
|
70 |
+
super().__init__(
|
71 |
+
primary_hue=primary_hue,
|
72 |
+
secondary_hue=secondary_hue,
|
73 |
+
neutral_hue=neutral_hue,
|
74 |
+
spacing_size=spacing_size,
|
75 |
+
radius_size=radius_size,
|
76 |
+
font=font,
|
77 |
+
font_mono=font_mono,
|
78 |
+
)
|
79 |
+
super().set(
|
80 |
+
button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
|
81 |
+
button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
|
82 |
+
button_primary_text_color="white",
|
83 |
+
button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
|
84 |
+
block_shadow="*shadow_drop_lg",
|
85 |
+
button_shadow="*shadow_drop_lg",
|
86 |
+
input_background_fill="zinc",
|
87 |
+
input_border_color="*secondary_300",
|
88 |
+
input_shadow="*shadow_drop",
|
89 |
+
input_shadow_focus="*shadow_drop_lg",
|
90 |
+
)
|
91 |
+
|
92 |
+
|
93 |
+
custom_theme = BlueTheme()
|
94 |
+
|
95 |
+
with gr.Blocks(theme=custom_theme, analytics_enabled=False, css=css) as demo:
|
96 |
+
with gr.Column():
|
97 |
+
gr.Markdown(
|
98 |
+
""" # 𓄿 Dolphin4ALL
|
99 |
+
8x7b quantized 2bit (q2_k)
|
100 |
+
Type in the box below and click the button to generate answers to your most pressing questions!
|
101 |
+
""")
|
102 |
+
|
103 |
+
with gr.Row():
|
104 |
+
with gr.Column(scale=3):
|
105 |
+
instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
|
106 |
+
|
107 |
+
with gr.Box():
|
108 |
+
gr.Markdown("**Answer**")
|
109 |
+
output = gr.Markdown(elem_id="q-output")
|
110 |
+
submit = gr.Button("Generate", variant="primary")
|
111 |
+
gr.Examples(
|
112 |
+
examples=examples,
|
113 |
+
inputs=[instruction],
|
114 |
+
cache_examples=False,
|
115 |
+
fn=process_example,
|
116 |
+
outputs=[output],
|
117 |
+
)
|
118 |
+
|
119 |
+
submit.click(generate, inputs=[instruction], outputs=[output])
|
120 |
+
instruction.submit(generate, inputs=[instruction], outputs=[output])
|
121 |
+
|
122 |
+
demo.queue(concurrency_count=1).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.14.0
|
2 |
+
huggingface-hub
|
3 |
+
llama-cpp-python==0.2.23
|