root commited on
Commit ·
d3541de
1
Parent(s): dee2bb2
fixed
Browse files
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
MODEL_ID = "play451/Moron"
|
|
|
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 7 |
|
| 8 |
client = InferenceClient(
|
|
@@ -10,11 +13,12 @@ client = InferenceClient(
|
|
| 10 |
token=HF_TOKEN,
|
| 11 |
)
|
| 12 |
|
|
|
|
| 13 |
def generate(prompt, max_tokens, temperature, top_p):
|
| 14 |
-
"""Generate a response from play451/Moron."""
|
| 15 |
prompt = (prompt or "").strip()
|
|
|
|
| 16 |
if not prompt:
|
| 17 |
-
return "
|
| 18 |
|
| 19 |
try:
|
| 20 |
result = client.text_generation(
|
|
@@ -25,37 +29,38 @@ def generate(prompt, max_tokens, temperature, top_p):
|
|
| 25 |
do_sample=True,
|
| 26 |
return_full_text=False,
|
| 27 |
)
|
|
|
|
| 28 |
return result
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
return (
|
| 31 |
"Inference failed.\n\n"
|
| 32 |
f"{type(e).__name__}: {e}\n\n"
|
| 33 |
-
"If the model requires
|
| 34 |
-
"secret
|
| 35 |
)
|
| 36 |
|
|
|
|
| 37 |
examples = [
|
| 38 |
["Hello! Introduce yourself."],
|
| 39 |
["Write a short explanation of what you can do."],
|
| 40 |
["Give me a creative idea for a Minecraft mod."],
|
| 41 |
]
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
theme=gr.themes.Soft(),
|
| 46 |
-
) as demo:
|
| 47 |
gr.Markdown(
|
| 48 |
"""
|
| 49 |
# 🤖 play451/Moron
|
| 50 |
|
| 51 |
Interactive demo for **[play451/Moron](https://huggingface.co/play451/Moron)**.
|
| 52 |
|
| 53 |
-
Enter a prompt
|
| 54 |
"""
|
| 55 |
)
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
-
with gr.Column(scale=
|
| 59 |
prompt = gr.Textbox(
|
| 60 |
label="Prompt",
|
| 61 |
placeholder="Enter your prompt...",
|
|
@@ -63,14 +68,17 @@ Enter a prompt below and generate text with the model.
|
|
| 63 |
)
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
-
generate_btn = gr.Button(
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
with gr.Column(scale=
|
| 70 |
output = gr.Textbox(
|
| 71 |
label="Generated text",
|
| 72 |
lines=14,
|
| 73 |
-
show_copy_button=True,
|
| 74 |
)
|
| 75 |
|
| 76 |
with gr.Accordion("Generation settings", open=False):
|
|
@@ -81,6 +89,7 @@ Enter a prompt below and generate text with the model.
|
|
| 81 |
step=1,
|
| 82 |
label="Max new tokens",
|
| 83 |
)
|
|
|
|
| 84 |
temperature = gr.Slider(
|
| 85 |
minimum=0.1,
|
| 86 |
maximum=2.0,
|
|
@@ -88,6 +97,7 @@ Enter a prompt below and generate text with the model.
|
|
| 88 |
step=0.05,
|
| 89 |
label="Temperature",
|
| 90 |
)
|
|
|
|
| 91 |
top_p = gr.Slider(
|
| 92 |
minimum=0.1,
|
| 93 |
maximum=1.0,
|
|
@@ -104,15 +114,35 @@ Enter a prompt below and generate text with the model.
|
|
| 104 |
|
| 105 |
generate_btn.click(
|
| 106 |
fn=generate,
|
| 107 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
outputs=output,
|
| 109 |
)
|
| 110 |
|
| 111 |
prompt.submit(
|
| 112 |
fn=generate,
|
| 113 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
outputs=output,
|
| 115 |
)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
if __name__ == "__main__":
|
| 118 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
import os
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
MODEL_ID = "play451/Moron"
|
| 8 |
+
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 10 |
|
| 11 |
client = InferenceClient(
|
|
|
|
| 13 |
token=HF_TOKEN,
|
| 14 |
)
|
| 15 |
|
| 16 |
+
|
| 17 |
def generate(prompt, max_tokens, temperature, top_p):
|
|
|
|
| 18 |
prompt = (prompt or "").strip()
|
| 19 |
+
|
| 20 |
if not prompt:
|
| 21 |
+
return ""
|
| 22 |
|
| 23 |
try:
|
| 24 |
result = client.text_generation(
|
|
|
|
| 29 |
do_sample=True,
|
| 30 |
return_full_text=False,
|
| 31 |
)
|
| 32 |
+
|
| 33 |
return result
|
| 34 |
+
|
| 35 |
except Exception as e:
|
| 36 |
return (
|
| 37 |
"Inference failed.\n\n"
|
| 38 |
f"{type(e).__name__}: {e}\n\n"
|
| 39 |
+
"If the model requires authentication, add an HF_TOKEN "
|
| 40 |
+
"secret to the Space settings."
|
| 41 |
)
|
| 42 |
|
| 43 |
+
|
| 44 |
examples = [
|
| 45 |
["Hello! Introduce yourself."],
|
| 46 |
["Write a short explanation of what you can do."],
|
| 47 |
["Give me a creative idea for a Minecraft mod."],
|
| 48 |
]
|
| 49 |
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 52 |
gr.Markdown(
|
| 53 |
"""
|
| 54 |
# 🤖 play451/Moron
|
| 55 |
|
| 56 |
Interactive demo for **[play451/Moron](https://huggingface.co/play451/Moron)**.
|
| 57 |
|
| 58 |
+
Enter a prompt and generate text with the model.
|
| 59 |
"""
|
| 60 |
)
|
| 61 |
|
| 62 |
with gr.Row():
|
| 63 |
+
with gr.Column(scale=1):
|
| 64 |
prompt = gr.Textbox(
|
| 65 |
label="Prompt",
|
| 66 |
placeholder="Enter your prompt...",
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
+
generate_btn = gr.Button(
|
| 72 |
+
"Generate",
|
| 73 |
+
variant="primary",
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
clear_btn = gr.Button("Clear")
|
| 77 |
|
| 78 |
+
with gr.Column(scale=1):
|
| 79 |
output = gr.Textbox(
|
| 80 |
label="Generated text",
|
| 81 |
lines=14,
|
|
|
|
| 82 |
)
|
| 83 |
|
| 84 |
with gr.Accordion("Generation settings", open=False):
|
|
|
|
| 89 |
step=1,
|
| 90 |
label="Max new tokens",
|
| 91 |
)
|
| 92 |
+
|
| 93 |
temperature = gr.Slider(
|
| 94 |
minimum=0.1,
|
| 95 |
maximum=2.0,
|
|
|
|
| 97 |
step=0.05,
|
| 98 |
label="Temperature",
|
| 99 |
)
|
| 100 |
+
|
| 101 |
top_p = gr.Slider(
|
| 102 |
minimum=0.1,
|
| 103 |
maximum=1.0,
|
|
|
|
| 114 |
|
| 115 |
generate_btn.click(
|
| 116 |
fn=generate,
|
| 117 |
+
inputs=[
|
| 118 |
+
prompt,
|
| 119 |
+
max_tokens,
|
| 120 |
+
temperature,
|
| 121 |
+
top_p,
|
| 122 |
+
],
|
| 123 |
outputs=output,
|
| 124 |
)
|
| 125 |
|
| 126 |
prompt.submit(
|
| 127 |
fn=generate,
|
| 128 |
+
inputs=[
|
| 129 |
+
prompt,
|
| 130 |
+
max_tokens,
|
| 131 |
+
temperature,
|
| 132 |
+
top_p,
|
| 133 |
+
],
|
| 134 |
outputs=output,
|
| 135 |
)
|
| 136 |
|
| 137 |
+
clear_btn.click(
|
| 138 |
+
fn=lambda: ("", ""),
|
| 139 |
+
inputs=None,
|
| 140 |
+
outputs=[prompt, output],
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
if __name__ == "__main__":
|
| 145 |
+
demo.launch(
|
| 146 |
+
theme=gr.themes.Soft(),
|
| 147 |
+
)
|
| 148 |
+
```
|