nezihtopaloglu commited on
Commit
bb63567
·
verified ·
1 Parent(s): 92077c5

Added text generation via Mistral-7B-instruct

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -2,12 +2,21 @@ import gradio as gr
2
  import torch
3
  import torchaudio
4
  from diffusers import StableDiffusionPipeline
 
5
  from TTS.api import TTS
6
  import moviepy.editor as mp
7
  import numpy as np
8
  import os
9
  from PIL import Image, ImageDraw, ImageFont
10
 
 
 
 
 
 
 
 
 
11
  def create_centered_title(image_size, text, max_font_size=50, min_font_size=10, padding=20):
12
  """Creates a title image with auto-adjusting text size to fit within the image."""
13
  title_img = Image.new("RGB", image_size, (0, 0, 0))
@@ -121,7 +130,9 @@ def process_text(text, movie_title, image_size, use_diffusion, num_steps):
121
 
122
  with gr.Blocks() as demo:
123
  gr.Markdown("# Text-to-Video Generator for YouTubers using AI 🎥")
124
- text_input = gr.Textbox(label="Enter your text")
 
 
125
  movie_title_input = gr.Textbox(label="Movie Title", value="")
126
  file_input = gr.File(label="Or upload a .txt file")
127
  image_size_input = gr.Radio(choices=["640x480", "800x600", "1024x768"], label="Select Image Size", value="640x480")
@@ -130,9 +141,11 @@ with gr.Blocks() as demo:
130
  process_btn = gr.Button("Generate Video")
131
  output_video = gr.Video()
132
 
133
- def handle_request(text, movie_title, file, image_size, use_diffusion, num_steps):
134
  if file is not None:
135
  text = open(file.name, "r").read()
 
 
136
  image_size_dict = {"640x480": (640, 480), "800x600": (800, 600), "1024x768": (1024, 768)}
137
  return process_text(text, movie_title, image_size_dict[image_size], use_diffusion, num_steps)
138
 
 
2
  import torch
3
  import torchaudio
4
  from diffusers import StableDiffusionPipeline
5
+ from transformers import pipeline
6
  from TTS.api import TTS
7
  import moviepy.editor as mp
8
  import numpy as np
9
  import os
10
  from PIL import Image, ImageDraw, ImageFont
11
 
12
+ def generate_script(topic):
13
+ """Uses an open-source LLM to generate an engaging script of 8-10 minutes."""
14
+ llm = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct")
15
+ prompt = (f"Write an engaging and informative script on the topic '{topic}'. "
16
+ "The text should take about 8-10 minutes to read aloud at a normal pace.")
17
+ response = llm(prompt, max_length=1500, do_sample=True, temperature=0.7)
18
+ return response[0]['generated_text']
19
+
20
  def create_centered_title(image_size, text, max_font_size=50, min_font_size=10, padding=20):
21
  """Creates a title image with auto-adjusting text size to fit within the image."""
22
  title_img = Image.new("RGB", image_size, (0, 0, 0))
 
130
 
131
  with gr.Blocks() as demo:
132
  gr.Markdown("# Text-to-Video Generator for YouTubers using AI 🎥")
133
+ text_input = gr.Textbox(label="Enter your text (or leave empty to use a topic)")
134
+ topic_input = gr.Textbox(label="Or enter a topic to generate text", placeholder="Example: The Future of AI")
135
+
136
  movie_title_input = gr.Textbox(label="Movie Title", value="")
137
  file_input = gr.File(label="Or upload a .txt file")
138
  image_size_input = gr.Radio(choices=["640x480", "800x600", "1024x768"], label="Select Image Size", value="640x480")
 
141
  process_btn = gr.Button("Generate Video")
142
  output_video = gr.Video()
143
 
144
+ def handle_request(text, topic, movie_title, file, image_size, use_diffusion, num_steps):
145
  if file is not None:
146
  text = open(file.name, "r").read()
147
+ elif not text and topic:
148
+ text = generate_script(topic)
149
  image_size_dict = {"640x480": (640, 480), "800x600": (800, 600), "1024x768": (1024, 768)}
150
  return process_text(text, movie_title, image_size_dict[image_size], use_diffusion, num_steps)
151