Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
generator = pipeline(
|
| 5 |
"text-generation",
|
|
@@ -8,6 +9,11 @@ generator = pipeline(
|
|
| 8 |
|
| 9 |
set_seed(42)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def generate_text(prompt):
|
| 12 |
if not prompt.strip():
|
| 13 |
return "Please enter a prompt to generate text."
|
|
@@ -22,7 +28,6 @@ def generate_text(prompt):
|
|
| 22 |
)
|
| 23 |
return response[0]["generated_text"]
|
| 24 |
|
| 25 |
-
# Define the Gradio interface
|
| 26 |
interface = gr.Interface(
|
| 27 |
fn=generate_text,
|
| 28 |
inputs=gr.Textbox(lines=4, placeholder="Type your prompt here..."),
|
|
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
import gradio as gr
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
generator = pipeline(
|
| 6 |
"text-generation",
|
|
|
|
| 9 |
|
| 10 |
set_seed(42)
|
| 11 |
|
| 12 |
+
def clean_output(text):
|
| 13 |
+
text = re.sub(r"=+\s*[^=]+?\s*=+", "", text)
|
| 14 |
+
text = re.sub(r"\s+", " ", text).strip()
|
| 15 |
+
return text
|
| 16 |
+
|
| 17 |
def generate_text(prompt):
|
| 18 |
if not prompt.strip():
|
| 19 |
return "Please enter a prompt to generate text."
|
|
|
|
| 28 |
)
|
| 29 |
return response[0]["generated_text"]
|
| 30 |
|
|
|
|
| 31 |
interface = gr.Interface(
|
| 32 |
fn=generate_text,
|
| 33 |
inputs=gr.Textbox(lines=4, placeholder="Type your prompt here..."),
|