Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,19 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
# Load a text-generation model.
|
| 5 |
# For demonstration, we're using GPT-2.
|
| 6 |
-
# For an adult-novel style,
|
| 7 |
generator = pipeline("text-generation", model="gpt2")
|
| 8 |
|
| 9 |
def generate_text(prompt, max_length):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Create the Gradio interface.
|
| 16 |
iface = gr.Interface(
|
|
|
|
| 3 |
|
| 4 |
# Load a text-generation model.
|
| 5 |
# For demonstration, we're using GPT-2.
|
| 6 |
+
# For an adult-novel style, consider a fine-tuned model or adjust parameters.
|
| 7 |
generator = pipeline("text-generation", model="gpt2")
|
| 8 |
|
| 9 |
def generate_text(prompt, max_length):
|
| 10 |
+
try:
|
| 11 |
+
# Generate text based on the prompt.
|
| 12 |
+
results = generator(prompt, max_length=max_length, do_sample=True, temperature=0.8)
|
| 13 |
+
return results[0]["generated_text"]
|
| 14 |
+
except Exception as e:
|
| 15 |
+
# Log the exception details for debugging
|
| 16 |
+
print("Error during text generation:", e)
|
| 17 |
+
# Return an error message for the user
|
| 18 |
+
return "An error occurred while generating text. Please try again with a shorter prompt or lower max length."
|
| 19 |
|
| 20 |
# Create the Gradio interface.
|
| 21 |
iface = gr.Interface(
|