Spaces:
Running
Running
Rename requirements.txt to app.py
Browse files- app.py +51 -0
- requirements.txt +0 -4
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
from diffusers import StableDiffusionPipeline
|
6 |
+
|
7 |
+
# Install necessary dependencies
|
8 |
+
os.system("pip install transformers diffusers gradio")
|
9 |
+
|
10 |
+
# Text Understanding with Hugging Face Transformers
|
11 |
+
def analyze_text(input_text):
|
12 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
13 |
+
summary = summarizer(input_text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
|
14 |
+
|
15 |
+
ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")
|
16 |
+
entities = ner_pipeline(input_text)
|
17 |
+
key_entities = [entity["word"] for entity in entities]
|
18 |
+
|
19 |
+
return summary, key_entities
|
20 |
+
|
21 |
+
# Generate Images Using Stable Diffusion
|
22 |
+
def generate_images(prompts):
|
23 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
24 |
+
sd_pipeline = StableDiffusionPipeline.from_pretrained(model_id)
|
25 |
+
images = []
|
26 |
+
for prompt in prompts:
|
27 |
+
image = sd_pipeline(prompt).images[0]
|
28 |
+
images.append(image)
|
29 |
+
return images
|
30 |
+
|
31 |
+
# Gradio App Interface
|
32 |
+
def generate_video_from_text(input_text):
|
33 |
+
# Analyze text
|
34 |
+
summary, key_entities = analyze_text(input_text)
|
35 |
+
|
36 |
+
# Generate prompts and images
|
37 |
+
prompts = [f"{entity}, cinematic, ultra-realistic" for entity in key_entities]
|
38 |
+
images = generate_images(prompts)
|
39 |
+
|
40 |
+
return summary, images
|
41 |
+
|
42 |
+
interface = gr.Interface(
|
43 |
+
fn=generate_video_from_text,
|
44 |
+
inputs="text",
|
45 |
+
outputs=["text", gr.outputs.Image(type="pil", label="Generated Images")],
|
46 |
+
title="Hugging Face Text Analysis & Image Generator",
|
47 |
+
description="Analyze text to extract key entities and generate corresponding images using open-source AI models."
|
48 |
+
)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
interface.launch()
|
requirements.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
groq
|
2 |
-
transformers
|
3 |
-
diffusers
|
4 |
-
gradio
|
|
|
|
|
|
|
|
|
|