Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +13 -0
- main.py +56 -0
- requirements.txt +0 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
|
7 |
+
WORKDIR /app
|
8 |
+
|
9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
+
|
12 |
+
COPY --chown=user . /app
|
13 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "main:app"]
|
main.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
+
import google.generativeai as genai
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
@app.route('/summarize', methods=['POST'])
|
7 |
+
def summarize():
|
8 |
+
print("flask running")
|
9 |
+
data = request.json
|
10 |
+
video_url = data.get('url')
|
11 |
+
import re
|
12 |
+
print(video_url)
|
13 |
+
def extract_youtube_video_id(url):
|
14 |
+
"""
|
15 |
+
Extracts the YouTube video ID from a given URL.
|
16 |
+
|
17 |
+
:param url: The YouTube video URL.
|
18 |
+
:return: The video ID if found, otherwise None.
|
19 |
+
"""
|
20 |
+
# Regular expression pattern to match YouTube video ID
|
21 |
+
pattern = r'(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})'
|
22 |
+
|
23 |
+
# Search for the pattern in the URL
|
24 |
+
match = re.search(pattern, url)
|
25 |
+
|
26 |
+
if match:
|
27 |
+
return match.group(1) # Return the video ID
|
28 |
+
else:
|
29 |
+
return None
|
30 |
+
|
31 |
+
video_id = extract_youtube_video_id(video_url)
|
32 |
+
print(video_id)
|
33 |
+
if not video_url:
|
34 |
+
return jsonify({'error': 'No URL provided'}), 400
|
35 |
+
|
36 |
+
try:
|
37 |
+
|
38 |
+
# Define the video ID
|
39 |
+
API_KEY="AIzaSyBwCqWaGW5ndo_zX-n3sTXMMI9L1di_KbA"
|
40 |
+
genai.configure(api_key=API_KEY)
|
41 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
42 |
+
|
43 |
+
# Combine all the transcript text into a single string
|
44 |
+
transcript_text = " ".join([entry['text'] for entry in transcript])
|
45 |
+
|
46 |
+
# Print or use the transcript text
|
47 |
+
#print(transcript_text)
|
48 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
49 |
+
response = model.generate_content(f"Summarize the youtube content given below(Just use plain text)\n{transcript_text}")
|
50 |
+
print(response.text)
|
51 |
+
return jsonify({'summary': response.text})
|
52 |
+
except Exception as e:
|
53 |
+
return jsonify({'error': str(e)}), 500
|
54 |
+
|
55 |
+
if __name__ == '__main__':
|
56 |
+
app.run(debug=True)
|
requirements.txt
ADDED
Binary file (122 Bytes). View file
|
|