Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
generator = pipeline('text-generation', model
|
| 5 |
|
| 6 |
def text_generator(sample, max_length):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
examples = [["Hello, I'm a language model", "45"], ["Hello, I'm a designer", "30"]]
|
| 11 |
|
| 12 |
css = """
|
| 13 |
-
|
| 14 |
-
.output-markdown{display:none !important}
|
| 15 |
-
.gr-button-primary {
|
| 16 |
-
z-index: 14;
|
| 17 |
-
height: 43px;
|
| 18 |
-
width: 130px;
|
| 19 |
-
left: 0px;
|
| 20 |
-
top: 0px;
|
| 21 |
-
padding: 0px;
|
| 22 |
-
cursor: pointer !important;
|
| 23 |
-
background: none rgb(17, 20, 45) !important;
|
| 24 |
-
border: none !important;
|
| 25 |
-
text-align: center !important;
|
| 26 |
-
font-family: Poppins !important;
|
| 27 |
-
font-size: 14px !important;
|
| 28 |
-
font-weight: 500 !important;
|
| 29 |
-
color: rgb(255, 255, 255) !important;
|
| 30 |
-
line-height: 1 !important;
|
| 31 |
-
border-radius: 12px !important;
|
| 32 |
-
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
| 33 |
-
box-shadow: none !important;
|
| 34 |
-
}
|
| 35 |
-
.gr-button-primary:hover{
|
| 36 |
-
z-index: 14;
|
| 37 |
-
height: 43px;
|
| 38 |
-
width: 130px;
|
| 39 |
-
left: 0px;
|
| 40 |
-
top: 0px;
|
| 41 |
-
padding: 0px;
|
| 42 |
-
cursor: pointer !important;
|
| 43 |
-
background: none rgb(66, 133, 244) !important;
|
| 44 |
-
border: none !important;
|
| 45 |
-
text-align: center !important;
|
| 46 |
-
font-family: Poppins !important;
|
| 47 |
-
font-size: 14px !important;
|
| 48 |
-
font-weight: 500 !important;
|
| 49 |
-
color: rgb(255, 255, 255) !important;
|
| 50 |
-
line-height: 1 !important;
|
| 51 |
-
border-radius: 12px !important;
|
| 52 |
-
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
| 53 |
-
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
|
| 54 |
-
}
|
| 55 |
-
.hover\:bg-orange-50:hover {
|
| 56 |
-
--tw-bg-opacity: 1 !important;
|
| 57 |
-
background-color: rgb(229,225,255) !important;
|
| 58 |
-
}
|
| 59 |
"""
|
| 60 |
-
|
| 61 |
-
demo.launch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 5 |
|
| 6 |
def text_generator(sample, max_length):
|
| 7 |
+
outputs = generator(sample, max_length=int(max_length), num_return_sequences=3)
|
| 8 |
+
return outputs[0]["generated_text"], outputs[1]["generated_text"], outputs[2]["generated_text"]
|
| 9 |
|
| 10 |
examples = [["Hello, I'm a language model", "45"], ["Hello, I'm a designer", "30"]]
|
| 11 |
|
| 12 |
css = """
|
| 13 |
+
# CSS content as before
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"""
|
| 15 |
+
|
| 16 |
+
# Modify the demo.launch call to include the api_name parameter
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=text_generator,
|
| 19 |
+
inputs=[gr.Textbox(lines=2, placeholder="Enter sample text here", label="Sample text"), gr.Textbox(lines=1, label="Length of generated text")],
|
| 20 |
+
outputs=[gr.Textbox(label="Generated text 1"), gr.Textbox(label="Generated text 2"), gr.Textbox(label="Generated text 3")],
|
| 21 |
+
title="Text Generator | Data Science Dojo",
|
| 22 |
+
examples=examples,
|
| 23 |
+
css=css
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch with api_name specified
|
| 27 |
+
demo.launch(debug=True, api_name="generate_text")
|