Sabbirr12 commited on
Commit
edea90f
·
verified ·
1 Parent(s): 27ed682

Update ultimate_ai_app_final.py

Browse files
Files changed (1) hide show
  1. ultimate_ai_app_final.py +42 -91
ultimate_ai_app_final.py CHANGED
@@ -1,91 +1,42 @@
1
- # ===========================
2
- # Ultimate AI App - Final Zero Interaction
3
- # ===========================
4
-
5
- # Required Libraries:
6
- # pip install diffusers transformers torch TTS moviepy pillow
7
-
8
- import torch
9
- from diffusers import StableDiffusionPipeline
10
- from TTS.api import TTS
11
- from transformers import pipeline
12
- from moviepy.editor import ImageSequenceClip
13
- import numpy as np
14
- from PIL import Image
15
-
16
- # ===========================
17
- # DEFAULT PROMPTS
18
- # ===========================
19
- DEFAULT_IMAGE_PROMPT = "3D, 4k, cinematic landscape, highly detailed"
20
- DEFAULT_VOICE_TEXT = "Hello! This is a fully automatic AI generation test."
21
- DEFAULT_TEXT_PROMPT = "Once upon a time in a futuristic world, AI created wonders."
22
- DEFAULT_VIDEO_PROMPT = "Fantasy landscape, cinematic, 4k"
23
-
24
- # ===========================
25
- # IMAGE GENERATION
26
- # ===========================
27
- def generate_image(prompt, save_path="generated_image.png"):
28
- print("Generating image...")
29
- pipe = StableDiffusionPipeline.from_pretrained(
30
- "runwayml/stable-diffusion-v1-5",
31
- torch_dtype=torch.float16
32
- )
33
- device = "cuda" if torch.cuda.is_available() else "cpu"
34
- pipe = pipe.to(device)
35
- image = pipe(prompt).images[0]
36
- image.save(save_path)
37
- print(f" Image saved as {save_path}")
38
-
39
- # ===========================
40
- # VOICE GENERATION
41
- # ===========================
42
- def generate_voice(text, save_path="generated_voice.wav"):
43
- print("Generating voice...")
44
- tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=True, gpu=torch.cuda.is_available())
45
- tts.tts_to_file(text=text, file_path=save_path)
46
- print(f"✅ Voice saved as {save_path}")
47
-
48
- # ===========================
49
- # TEXT GENERATION
50
- # ===========================
51
- def generate_text(prompt, max_length=100):
52
- print("Generating text...")
53
- generator = pipeline('text-generation', model='gpt2')
54
- result = generator(prompt, max_length=max_length, num_return_sequences=1)
55
- with open("generated_text.txt", "w", encoding="utf-8") as f:
56
- f.write(result[0]['generated_text'])
57
- print(f"✅ Text saved as generated_text.txt")
58
-
59
- # ===========================
60
- # VIDEO GENERATION
61
- # ===========================
62
- def generate_video(prompt, num_frames=10, save_path="generated_video.mp4"):
63
- print("Generating video...")
64
- pipe = StableDiffusionPipeline.from_pretrained(
65
- "runwayml/stable-diffusion-v1-5",
66
- torch_dtype=torch.float16
67
- )
68
- device = "cuda" if torch.cuda.is_available() else "cpu"
69
- pipe = pipe.to(device)
70
-
71
- frames = []
72
- for i in range(num_frames):
73
- image = pipe(prompt).images[0]
74
- frames.append(image.convert("RGB"))
75
-
76
- clip = ImageSequenceClip([np.array(frame) for frame in frames], fps=2)
77
- clip.write_videofile(save_path)
78
- print(f"✅ Video saved as {save_path}")
79
-
80
- # ===========================
81
- # MAIN - ZERO INTERACTION
82
- # ===========================
83
- if __name__ == "__main__":
84
- print("=== Ultimate AI App - Final Zero Interaction ===\n")
85
-
86
- generate_image(DEFAULT_IMAGE_PROMPT)
87
- generate_voice(DEFAULT_VOICE_TEXT)
88
- generate_text(DEFAULT_TEXT_PROMPT)
89
- generate_video(DEFAULT_VIDEO_PROMPT)
90
-
91
- print("\n🎉 All tasks completed! All files are saved in this folder.")
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline, DiffusionPipeline
3
+ import torch, imageio
4
+
5
+ # Load Image Generator
6
+ img_model = "runwayml/stable-diffusion-v1-5"
7
+ img_pipe = StableDiffusionPipeline.from_pretrained(img_model, torch_dtype=torch.float32)
8
+ img_pipe = img_pipe.to("cpu")
9
+
10
+ # Load Video Generator
11
+ vid_model = "damo-vilab/text-to-video-ms-1.7b"
12
+ vid_pipe = DiffusionPipeline.from_pretrained(vid_model, torch_dtype=torch.float32)
13
+ vid_pipe = vid_pipe.to("cpu")
14
+
15
+ # Image generation function
16
+ def generate_image(prompt):
17
+ image = img_pipe(prompt).images[0]
18
+ return image
19
+
20
+ # Video generation function
21
+ def generate_video(prompt):
22
+ video_frames = vid_pipe(prompt, num_frames=8).frames
23
+ output_path = "output.mp4"
24
+ imageio.mimsave(output_path, video_frames, fps=8)
25
+ return output_path
26
+
27
+ # Gradio Tabs UI
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("## 🎨 Free AI Image + Video Generator")
30
+ with gr.Tab("🖼️ Image Generator"):
31
+ text_in = gr.Textbox(label="ছবির জন্য প্রম্পট লিখুন")
32
+ img_out = gr.Image(type="pil")
33
+ btn1 = gr.Button("Generate Image")
34
+ btn1.click(generate_image, inputs=text_in, outputs=img_out)
35
+
36
+ with gr.Tab("🎬 Video Generator"):
37
+ text_in2 = gr.Textbox(label="ভিডিওর জন্য প্রম্পট লিখুন")
38
+ vid_out = gr.Video()
39
+ btn2 = gr.Button("Generate Video")
40
+ btn2.click(generate_video, inputs=text_in2, outputs=vid_out)
41
+
42
+ demo.launch()