sh20raj commited on
Commit
2756a35
·
1 Parent(s): bab5260
Files changed (6) hide show
  1. .gitignore +2 -1
  2. README copy.md +13 -0
  3. app copy.py +75 -0
  4. requirements copy.txt +53 -0
  5. upload.py +62 -0
  6. urluploader.py +62 -0
.gitignore CHANGED
@@ -1 +1,2 @@
1
- venv
 
 
1
+ venv
2
+ downloads
README copy.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Autoinsta
3
+ emoji: 🦀
4
+ colorFrom: pink
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.37.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app copy.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import streamlit as st
3
+ from instagrapi import Client
4
+ import requests
5
+ from pathlib import Path
6
+ import os
7
+ from moviepy.editor import VideoFileClip
8
+ from PIL import Image
9
+
10
+ # Your Instagram credentials
11
+ username = "droidcv1"
12
+ password = ";ya_#GkM,KND6?$"
13
+
14
+ # Initialize the client
15
+ cl = Client()
16
+
17
+ # Add a delay before login
18
+ time.sleep(5)
19
+
20
+ # Login to Instagram
21
+ try:
22
+ cl.login(username, password)
23
+ except Exception as e:
24
+ st.error(f'Login failed: {e}')
25
+ st.stop()
26
+
27
+ # Function to download video
28
+ def download_video(url, filename):
29
+ response = requests.get(url, stream=True)
30
+ if response.status_code == 200:
31
+ with open(filename, 'wb') as f:
32
+ for chunk in response.iter_content(1024):
33
+ f.write(chunk)
34
+ return filename
35
+
36
+ # Function to generate thumbnail
37
+ def generate_thumbnail(video_path):
38
+ clip = VideoFileClip(str(video_path))
39
+ frame = clip.get_frame(1) # Get a frame at 1 second
40
+ thumbnail_path = str(video_path) + ".jpg"
41
+ im = Image.fromarray(frame)
42
+ im.save(thumbnail_path)
43
+ return thumbnail_path
44
+
45
+ # Function to upload video and return the reel URL
46
+ def upload_video(video_path, caption):
47
+ thumbnail_path = generate_thumbnail(video_path)
48
+ media = cl.clip_upload(video_path, caption=caption, thumbnail=thumbnail_path)
49
+ return f"https://www.instagram.com/reel/{media.pk}/"
50
+
51
+ # Directory to save downloaded videos
52
+ download_dir = Path("downloads")
53
+ download_dir.mkdir(exist_ok=True)
54
+
55
+ st.title('Instagram Reels Uploader')
56
+
57
+ urls = st.text_area('Enter video URLs (one per line):')
58
+
59
+ if st.button('Upload Videos'):
60
+ if urls:
61
+ video_urls = urls.splitlines()
62
+ for idx, video_url in enumerate(video_urls, start=1):
63
+ with st.spinner(f'Downloading video {idx}...'):
64
+ video_path = download_video(video_url, download_dir / f"video_{idx}.mp4")
65
+ caption = f"Sample video {idx}"
66
+ with st.spinner(f'Uploading video {idx}...'):
67
+ try:
68
+ reel_url = upload_video(video_path, caption)
69
+ st.success(f'Uploaded video {idx} URL: {reel_url}')
70
+ except Exception as e:
71
+ st.error(f'Failed to upload video {idx}: {e}')
72
+ os.remove(video_path)
73
+ os.remove(video_path.with_suffix('.mp4.jpg'))
74
+ else:
75
+ st.warning('Please enter at least one video URL.')
requirements copy.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.3.0
2
+ annotated-types==0.7.0
3
+ attrs==23.2.0
4
+ blinker==1.8.2
5
+ cachetools==5.4.0
6
+ certifi==2024.7.4
7
+ charset-normalizer==3.3.2
8
+ click==8.1.7
9
+ decorator==4.4.2
10
+ gitdb==4.0.11
11
+ GitPython==3.1.43
12
+ idna==3.7
13
+ imageio==2.34.2
14
+ imageio-ffmpeg==0.5.1
15
+ instagrapi==2.1.2
16
+ Jinja2==3.1.4
17
+ jsonschema==4.23.0
18
+ jsonschema-specifications==2023.12.1
19
+ markdown-it-py==3.0.0
20
+ MarkupSafe==2.1.5
21
+ mdurl==0.1.2
22
+ moviepy==1.0.3
23
+ numpy==2.0.1
24
+ packaging==24.1
25
+ pandas==2.2.2
26
+ pillow==10.4.0
27
+ proglog==0.1.10
28
+ protobuf==5.27.2
29
+ pyarrow==17.0.0
30
+ pycryptodomex==3.20.0
31
+ pydantic==2.7.1
32
+ pydantic_core==2.18.2
33
+ pydeck==0.9.1
34
+ Pygments==2.18.0
35
+ PySocks==1.7.1
36
+ python-dateutil==2.9.0.post0
37
+ pytz==2024.1
38
+ referencing==0.35.1
39
+ requests==2.32.3
40
+ rich==13.7.1
41
+ rpds-py==0.19.1
42
+ setuptools==72.1.0
43
+ six==1.16.0
44
+ smmap==5.0.1
45
+ streamlit==1.37.0
46
+ tenacity==8.5.0
47
+ toml==0.10.2
48
+ toolz==0.12.1
49
+ tornado==6.4.1
50
+ tqdm==4.66.4
51
+ typing_extensions==4.12.2
52
+ tzdata==2024.1
53
+ urllib3==2.2.2
upload.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from instagrapi import Client
2
+ import requests
3
+ from pathlib import Path
4
+ import os
5
+ from moviepy.editor import VideoFileClip
6
+ from PIL import Image
7
+
8
+ # Your Instagram credentials
9
+ username = "droidcv1"
10
+ password = ";ya_#GkM,KND6?$"
11
+
12
+ # Initialize the client
13
+ cl = Client()
14
+
15
+ # Login to Instagram
16
+ cl.login(username, password)
17
+
18
+ # Array of sample video URLs
19
+ video_urls = [
20
+ "https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
21
+ "https://samplelib.com/lib/preview/mp4/sample-10s.mp4",
22
+ "https://samplelib.com/lib/preview/mp4/sample-15s.mp4"
23
+ ]
24
+
25
+ # Function to download video
26
+ def download_video(url, filename):
27
+ response = requests.get(url, stream=True)
28
+ if response.status_code == 200:
29
+ with open(filename, 'wb') as f:
30
+ for chunk in response.iter_content(1024):
31
+ f.write(chunk)
32
+ return filename
33
+
34
+ # Function to generate thumbnail
35
+ def generate_thumbnail(video_path):
36
+ clip = VideoFileClip(str(video_path))
37
+ frame = clip.get_frame(1) # Get a frame at 1 second
38
+ thumbnail_path = str(video_path) + ".jpg"
39
+ im = Image.fromarray(frame)
40
+ im.save(thumbnail_path)
41
+ return thumbnail_path
42
+
43
+ # Function to upload video and return the reel URL
44
+ def upload_video(video_path, caption):
45
+ thumbnail_path = generate_thumbnail(video_path)
46
+ media = cl.clip_upload(video_path, caption=caption, thumbnail=thumbnail_path)
47
+ return f"https://www.instagram.com/reel/{media.pk}/"
48
+
49
+ # Directory to save downloaded videos
50
+ download_dir = Path("downloads")
51
+ download_dir.mkdir(exist_ok=True)
52
+
53
+ # Loop through video URLs, download, and upload each one
54
+ for idx, video_url in enumerate(video_urls, start=1):
55
+ video_path = download_video(video_url, download_dir / f"video_{idx}.mp4")
56
+ caption = f"Sample video {idx}"
57
+ reel_url = upload_video(video_path, caption)
58
+ print(f"Uploaded video {idx} URL: {reel_url}")
59
+
60
+ # Delete the video and thumbnail from the server after uploading
61
+ os.remove(video_path)
62
+ os.remove(video_path.with_suffix('.mp4.jpg'))
urluploader.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from instagrapi import Client
2
+ import requests
3
+ from pathlib import Path
4
+ import os
5
+ from moviepy.editor import VideoFileClip
6
+ from PIL import Image
7
+
8
+ # Your Instagram credentials
9
+ username = "droidcv1"
10
+ password = ";ya_#GkM,KND6?$"
11
+
12
+ # Initialize the client
13
+ cl = Client()
14
+
15
+ # Login to Instagram
16
+ cl.login(username, password)
17
+
18
+ # Array of sample video URLs
19
+ video_urls = [
20
+ "https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
21
+ "https://samplelib.com/lib/preview/mp4/sample-10s.mp4",
22
+ "https://samplelib.com/lib/preview/mp4/sample-15s.mp4"
23
+ ]
24
+
25
+ # Function to download video
26
+ def download_video(url, filename):
27
+ response = requests.get(url, stream=True)
28
+ if response.status_code == 200:
29
+ with open(filename, 'wb') as f:
30
+ for chunk in response.iter_content(1024):
31
+ f.write(chunk)
32
+ return filename
33
+
34
+ # Function to generate thumbnail
35
+ def generate_thumbnail(video_path):
36
+ clip = VideoFileClip(str(video_path))
37
+ frame = clip.get_frame(1) # Get a frame at 1 second
38
+ thumbnail_path = str(video_path) + ".jpg"
39
+ im = Image.fromarray(frame)
40
+ im.save(thumbnail_path)
41
+ return thumbnail_path
42
+
43
+ # Function to upload video and return the reel URL
44
+ def upload_video(video_path, caption):
45
+ thumbnail_path = generate_thumbnail(video_path)
46
+ media = cl.clip_upload(video_path, caption=caption, thumbnail=thumbnail_path)
47
+ return f"https://www.instagram.com/reel/{media.pk}/"
48
+
49
+ # Directory to save downloaded videos
50
+ download_dir = Path("downloads")
51
+ download_dir.mkdir(exist_ok=True)
52
+
53
+ # Loop through video URLs, download, and upload each one
54
+ for idx, video_url in enumerate(video_urls, start=1):
55
+ video_path = download_video(video_url, download_dir / f"video_{idx}.mp4")
56
+ caption = f"Sample video {idx}"
57
+ reel_url = upload_video(video_path, caption)
58
+ print(f"Uploaded video {idx} URL: {reel_url}")
59
+
60
+ # Delete the video and thumbnail from the server after uploading
61
+ os.remove(video_path)
62
+ os.remove(video_path.with_suffix('.mp4.jpg'))