import gradio as gr from transformers import pipeline # Load AI models caption_generator = pipeline("text-generation", model="Xenova/distilgpt2") summarizer = pipeline("summarization", model="Xenova/t5-small") sentiment_analyzer = pipeline("sentiment-analysis", model="Xenova/distilbert-base-uncased-finetuned-sst-2-english") # Functions def generate_caption(text): result = caption_generator(text, max_length=50) return result[0]['generated_text'] def summarize_text(text): result = summarizer(text, max_length=60, min_length=20, do_sample=False) return result[0]['summary_text'] def analyze_sentiment(text): result = sentiment_analyzer(text) return f"{result[0]['label']} ({result[0]['score']:.2f})" # Gradio UI with gr.Blocks() as demo: gr.Markdown("# AI Tools Website\nGenerate captions, summarize text, analyze sentiment!") with gr.Tab("Generate Caption"): inp1 = gr.Textbox(label="Enter text") out1 = gr.Textbox(label="Caption") btn1 = gr.Button("Generate Caption") btn1.click(generate_caption, inp1, out1) with gr.Tab("Summarize"): inp2 = gr.Textbox(label="Enter text") out2 = gr.Textbox(label="Summary") btn2 = gr.Button("Summarize") btn2.click(summarize_text, inp2, out2) with gr.Tab("Sentiment"): inp3 = gr.Textbox(label="Enter text") out3 = gr.Textbox(label="Sentiment") btn3 = gr.Button("Analyze Sentiment") btn3.click(analyze_sentiment, inp3, out3) demo.launch()