Spaces:
Sleeping
Sleeping
File size: 927 Bytes
12363c6 447a3b1 b885022 447a3b1 b885022 12363c6 b885022 65eb245 b885022 2e6796d b885022 447a3b1 2e6796d 82307ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from transformers import pipeline
import gradio as gr
# Load model safely
try:
model = pipeline("text-generation", model="ButteredToast/ToastBot")
except Exception as e:
print(f"Error loading model: {e}")
model = None # Prevent crashes
# Define text generation function
def generate_text(input_text):
if model is None:
return "Error: Model could not be loaded. Check your Hugging Face space logs."
try:
output = model(input_text, max_length=30, truncation=True) # Explicit truncation added
return output[0]["generated_text"]
except Exception as e:
return f"Error generating text: {e}"
# Set up Gradio interface with API enabled
demo = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="ToastBot AI",
description="Chat with ToastBot, your AI assistant!"
)
# Enable API mode for external requests
demo.launch(share=True)
|