Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,36 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
tokenizer=tokenizer,
|
20 |
-
max_new_tokens=512,
|
21 |
-
do_sample=True,
|
22 |
-
temperature=0.7,
|
23 |
-
top_p=0.9
|
24 |
-
)
|
25 |
-
|
26 |
-
def chat(user_input, history):
|
27 |
-
history = history or []
|
28 |
-
prompt = ""
|
29 |
-
|
30 |
-
for user_msg, bot_msg in history:
|
31 |
-
prompt += f"<|user|>{user_msg}<|assistant|>{bot_msg}"
|
32 |
-
prompt += f"<|user|>{user_input}<|assistant|>"
|
33 |
-
|
34 |
-
result = pipe(prompt)[0]['generated_text']
|
35 |
-
reply = result.split("<|assistant|>")[-1].strip()
|
36 |
-
|
37 |
-
history.append((user_input, reply))
|
38 |
-
return reply, history
|
39 |
-
|
40 |
-
with gr.Blocks(css="footer {display:none !important}") as demo:
|
41 |
-
gr.Markdown("<h1 style='text-align:center;'>💬 Free ChatGPT-like Assistant (No API Key)</h1>")
|
42 |
-
chatbot = gr.Chatbot()
|
43 |
-
msg = gr.Textbox(label="ඔබේ ප්රශ්නය")
|
44 |
-
clear = gr.Button("Clear Chat")
|
45 |
-
state = gr.State([])
|
46 |
-
|
47 |
-
msg.submit(chat, [msg, state], [chatbot, state])
|
48 |
-
clear.click(lambda: ([], []), None, [chatbot, state])
|
49 |
-
|
50 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
from pytube import YouTube
|
4 |
+
|
5 |
+
def download_youtube_video(url: str):
|
6 |
+
try:
|
7 |
+
# YouTube object එක initialize කරලා ලබා ගන්නවා
|
8 |
+
yt = YouTube(url)
|
9 |
+
# ප්රගතිමත් (progressive) MP4 streams අතරින් උසම resolution එක select කරනවා
|
10 |
+
stream = yt.streams.filter(progressive=True, file_extension='mp4').get_highest_resolution()
|
11 |
+
|
12 |
+
# Temporary downloads folder එකක් check/තනන්න
|
13 |
+
download_folder = "downloads"
|
14 |
+
if not os.path.exists(download_folder):
|
15 |
+
os.makedirs(download_folder)
|
16 |
+
|
17 |
+
# Video download කිරීම සහ output path එක return කිරීම
|
18 |
+
output_path = stream.download(output_path=download_folder)
|
19 |
+
return output_path
|
20 |
+
|
21 |
+
except Exception as e:
|
22 |
+
# Error එකක් නම්, error message එක return කරනවා
|
23 |
+
return f"Error: {str(e)}"
|
24 |
+
|
25 |
+
# Gradio Interface එක Define කරනවා
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=download_youtube_video,
|
28 |
+
inputs=gr.Textbox(lines=1, placeholder="YouTube video URL එක ඇතුලත් කරන්න..."),
|
29 |
+
outputs="file",
|
30 |
+
title="YouTube Video Downloader",
|
31 |
+
description="YouTube video URL එකක් ඇතුලත් කරන්න සහ ඒ video එක උසම resolution එකෙන් download කරගන්න. API key අවශ්ය නැත."
|
32 |
)
|
33 |
|
34 |
+
# App Launch කිරීම
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|