Spaces:
Running
Running
# app.py | |
import os | |
import gradio as gr | |
from transformers import pipeline | |
from diffusers import StableDiffusionPipeline | |
# Install necessary dependencies | |
os.system("pip install transformers diffusers gradio") | |
# Text Understanding with Hugging Face Transformers | |
def analyze_text(input_text): | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
summary = summarizer(input_text, max_length=50, min_length=10, do_sample=False)[0]['summary_text'] | |
ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english") | |
entities = ner_pipeline(input_text) | |
key_entities = [entity["word"] for entity in entities] | |
return summary, key_entities | |
# Generate Images Using Stable Diffusion | |
def generate_images(prompts): | |
model_id = "CompVis/stable-diffusion-v1-4" | |
sd_pipeline = StableDiffusionPipeline.from_pretrained(model_id) | |
images = [] | |
for prompt in prompts: | |
image = sd_pipeline(prompt).images[0] | |
images.append(image) | |
return images | |
# Gradio App Interface | |
def generate_video_from_text(input_text): | |
# Analyze text | |
summary, key_entities = analyze_text(input_text) | |
# Generate prompts and images | |
prompts = [f"{entity}, cinematic, ultra-realistic" for entity in key_entities] | |
images = generate_images(prompts) | |
return summary, images | |
interface = gr.Interface( | |
fn=generate_video_from_text, | |
inputs="text", | |
outputs=["text", gr.outputs.Image(type="pil", label="Generated Images")], | |
title="Hugging Face Text Analysis & Image Generator", | |
description="Analyze text to extract key entities and generate corresponding images using open-source AI models." | |
) | |
if __name__ == "__main__": | |
interface.launch() | |