Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,12 @@ import os
|
|
2 |
import random
|
3 |
import gradio as gr
|
4 |
from groq import Groq
|
|
|
5 |
|
6 |
client = Groq(
|
7 |
-
api_key
|
8 |
)
|
9 |
-
|
10 |
def create_history_messages(history):
|
11 |
history_messages = [{"role": "user", "content": m[0]} for m in history]
|
12 |
history_messages.extend([{"role": "assistant", "content": m[1]} for m in history])
|
@@ -19,7 +20,7 @@ def generate_response(prompt, history, model, temperature, max_tokens, top_p, se
|
|
19 |
|
20 |
if seed == 0:
|
21 |
seed = random.randint(1, 100000)
|
22 |
-
|
23 |
stream = client.chat.completions.create(
|
24 |
messages=messages,
|
25 |
model=model,
|
@@ -40,6 +41,23 @@ def generate_response(prompt, history, model, temperature, max_tokens, top_p, se
|
|
40 |
|
41 |
return response
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
additional_inputs = [
|
44 |
gr.Dropdown(choices=["llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma-7b-it"], value="llama3-70b-8192", label="Model"),
|
45 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."),
|
@@ -48,16 +66,26 @@ additional_inputs = [
|
|
48 |
gr.Number(precision=0, value=42, label="Seed", info="A starting point to initiate generation, use 0 for random")
|
49 |
]
|
50 |
|
51 |
-
theme
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
fn=generate_response,
|
58 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
59 |
-
additional_inputs=additional_inputs,
|
60 |
-
title="YTSHorts Maker",
|
61 |
-
description="Powered by GROQ, MoviePy, and other tools.",
|
62 |
-
theme="Soft",
|
63 |
-
).launch()
|
|
|
2 |
import random
|
3 |
import gradio as gr
|
4 |
from groq import Groq
|
5 |
+
from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
|
6 |
|
7 |
client = Groq(
|
8 |
+
api_key=os.environ.get("Groq_Api_Key")
|
9 |
)
|
10 |
+
|
11 |
def create_history_messages(history):
|
12 |
history_messages = [{"role": "user", "content": m[0]} for m in history]
|
13 |
history_messages.extend([{"role": "assistant", "content": m[1]} for m in history])
|
|
|
20 |
|
21 |
if seed == 0:
|
22 |
seed = random.randint(1, 100000)
|
23 |
+
|
24 |
stream = client.chat.completions.create(
|
25 |
messages=messages,
|
26 |
model=model,
|
|
|
41 |
|
42 |
return response
|
43 |
|
44 |
+
def process_video(video_path, text):
|
45 |
+
video = VideoFileClip(video_path).subclip(0, min(60, VideoFileClip(video_path).duration))
|
46 |
+
video = video.resize(height=1920).crop(x1=video.w // 2 - 540, x2=video.w // 2 + 540)
|
47 |
+
|
48 |
+
text_lines = text.split()
|
49 |
+
text = "\n".join([" ".join(text_lines[i:i+8]) for i in range(0, len(text_lines), 8)])
|
50 |
+
|
51 |
+
text_clip = TextClip(text, fontsize=70, color='white', size=video.size, method='caption')
|
52 |
+
text_clip = text_clip.set_position('center').set_duration(video.duration)
|
53 |
+
|
54 |
+
final = CompositeVideoClip([video, text_clip])
|
55 |
+
|
56 |
+
output_path = "output.mp4"
|
57 |
+
final.write_videofile(output_path, codec="libx264")
|
58 |
+
|
59 |
+
return output_path
|
60 |
+
|
61 |
additional_inputs = [
|
62 |
gr.Dropdown(choices=["llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma-7b-it"], value="llama3-70b-8192", label="Model"),
|
63 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."),
|
|
|
66 |
gr.Number(precision=0, value=42, label="Seed", info="A starting point to initiate generation, use 0 for random")
|
67 |
]
|
68 |
|
69 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="red", secondary_hue="pink")) as demo:
|
70 |
+
with gr.Tabs():
|
71 |
+
with gr.TabItem("Chat"):
|
72 |
+
gr.ChatInterface(
|
73 |
+
fn=generate_response,
|
74 |
+
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
75 |
+
additional_inputs=additional_inputs,
|
76 |
+
title="YTSHorts Maker",
|
77 |
+
description="Powered by GROQ, MoviePy, and other tools.",
|
78 |
+
)
|
79 |
+
with gr.TabItem("Video Processing"):
|
80 |
+
video_input = gr.Video(label="Upload Video")
|
81 |
+
text_input = gr.Textbox(lines=5, label="Text (8 words max per line)")
|
82 |
+
process_button = gr.Button("Process Video")
|
83 |
+
video_output = gr.Video(label="Processed Video")
|
84 |
+
|
85 |
+
process_button.click(
|
86 |
+
fn=process_video,
|
87 |
+
inputs=[video_input, text_input],
|
88 |
+
outputs=video_output,
|
89 |
+
)
|
90 |
|
91 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|