Spaces:
Runtime error
Runtime error
Added share to community button
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import os
|
|
3 |
import gradio as gr
|
4 |
from text_generation import Client
|
5 |
|
|
|
|
|
6 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
7 |
API_URL = " https://api-inference.huggingface.co/models/BigCode/octocoder"
|
8 |
|
@@ -24,7 +26,8 @@ client = Client(
|
|
24 |
headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
25 |
)
|
26 |
|
27 |
-
|
|
|
28 |
if query.endswith("."):
|
29 |
prompt = f"Question: {query}\n\nAnswer:"
|
30 |
else:
|
@@ -72,6 +75,8 @@ monospace_css = """
|
|
72 |
}
|
73 |
"""
|
74 |
|
|
|
|
|
75 |
description = """
|
76 |
<div style="text-align: center;">
|
77 |
<center><img src='https://raw.githubusercontent.com/bigcode-project/octopack/31f3320f098703c7910e43492c39366eeea68d83/banner.png' width='70%'/></center>
|
@@ -87,7 +92,6 @@ description = """
|
|
87 |
disclaimer = """⚠️<b>Any use or sharing of this demo constitues your acceptance of the BigCode [OpenRAIL-M](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) License Agreement and the use restrictions included within.</b>\
|
88 |
<br>**Intended Use**: this app and its [supporting model](https://huggingface.co/bigcode) are provided for demonstration purposes; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card.](https://huggingface.co/bigcode)"""
|
89 |
|
90 |
-
|
91 |
examples = [
|
92 |
['Please write a function in Python that performs bubble sort.', 256],
|
93 |
['''Explain the following piece of code
|
@@ -98,11 +102,12 @@ def count_unique(s):
|
|
98 |
valid_sentence = "".join(valid_chars)
|
99 |
uniques = set(valid_sentence.split(" "))
|
100 |
return len(uniques)''', 512],
|
101 |
-
[
|
|
|
|
|
102 |
['Write a html and css code to render a clock', 8000],
|
103 |
]
|
104 |
|
105 |
-
|
106 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
107 |
with gr.Column():
|
108 |
gr.Markdown(description)
|
@@ -161,6 +166,12 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
161 |
submit = gr.Button("Generate", variant="primary")
|
162 |
output = gr.Code(elem_id="q-output", lines=30, label="Output")
|
163 |
gr.Markdown(disclaimer)
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
gr.Examples(
|
165 |
examples=examples,
|
166 |
inputs=[instruction, max_new_tokens],
|
@@ -174,4 +185,5 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
174 |
inputs=[instruction, temperature, max_new_tokens, top_p, repetition_penalty],
|
175 |
outputs=[output],
|
176 |
)
|
|
|
177 |
demo.queue(concurrency_count=16).launch(debug=True)
|
|
|
3 |
import gradio as gr
|
4 |
from text_generation import Client
|
5 |
|
6 |
+
from share_btn import community_icon_html, loading_icon_html, share_js, share_btn_css
|
7 |
+
|
8 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
9 |
API_URL = " https://api-inference.huggingface.co/models/BigCode/octocoder"
|
10 |
|
|
|
26 |
headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
27 |
)
|
28 |
|
29 |
+
|
30 |
+
def generate(query: str, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, ):
|
31 |
if query.endswith("."):
|
32 |
prompt = f"Question: {query}\n\nAnswer:"
|
33 |
else:
|
|
|
75 |
}
|
76 |
"""
|
77 |
|
78 |
+
css += share_btn_css + monospace_css
|
79 |
+
|
80 |
description = """
|
81 |
<div style="text-align: center;">
|
82 |
<center><img src='https://raw.githubusercontent.com/bigcode-project/octopack/31f3320f098703c7910e43492c39366eeea68d83/banner.png' width='70%'/></center>
|
|
|
92 |
disclaimer = """⚠️<b>Any use or sharing of this demo constitues your acceptance of the BigCode [OpenRAIL-M](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) License Agreement and the use restrictions included within.</b>\
|
93 |
<br>**Intended Use**: this app and its [supporting model](https://huggingface.co/bigcode) are provided for demonstration purposes; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card.](https://huggingface.co/bigcode)"""
|
94 |
|
|
|
95 |
examples = [
|
96 |
['Please write a function in Python that performs bubble sort.', 256],
|
97 |
['''Explain the following piece of code
|
|
|
102 |
valid_sentence = "".join(valid_chars)
|
103 |
uniques = set(valid_sentence.split(" "))
|
104 |
return len(uniques)''', 512],
|
105 |
+
[
|
106 |
+
'Write an efficient Python function that takes a given text and returns its Morse code equivalent without using any third party library',
|
107 |
+
512],
|
108 |
['Write a html and css code to render a clock', 8000],
|
109 |
]
|
110 |
|
|
|
111 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
112 |
with gr.Column():
|
113 |
gr.Markdown(description)
|
|
|
166 |
submit = gr.Button("Generate", variant="primary")
|
167 |
output = gr.Code(elem_id="q-output", lines=30, label="Output")
|
168 |
gr.Markdown(disclaimer)
|
169 |
+
with gr.Group(elem_id="share-btn-container"):
|
170 |
+
community_icon = gr.HTML(community_icon_html, visible=True)
|
171 |
+
loading_icon = gr.HTML(loading_icon_html, visible=True)
|
172 |
+
share_button = gr.Button(
|
173 |
+
"Share to community", elem_id="share-btn", visible=True
|
174 |
+
)
|
175 |
gr.Examples(
|
176 |
examples=examples,
|
177 |
inputs=[instruction, max_new_tokens],
|
|
|
185 |
inputs=[instruction, temperature, max_new_tokens, top_p, repetition_penalty],
|
186 |
outputs=[output],
|
187 |
)
|
188 |
+
share_button.click(None, [], [], _js=share_js)
|
189 |
demo.queue(concurrency_count=16).launch(debug=True)
|