Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -177,27 +177,43 @@ def generate_optimized_content(api_key, summarized_transcript):
|
|
| 177 |
except Exception as e:
|
| 178 |
print(f"Error generating content: {e}")
|
| 179 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def youtube_seo_pipeline(youtube_url):
|
| 181 |
-
|
|
|
|
| 182 |
if not YOUTUBE_API_KEY or not OPENAI_API_KEY:
|
| 183 |
return "API keys missing! Please check environment variables."
|
| 184 |
|
|
|
|
| 185 |
video_id = extract_video_id(youtube_url)
|
| 186 |
if not video_id:
|
| 187 |
return "Invalid YouTube URL."
|
| 188 |
|
|
|
|
|
|
|
|
|
|
| 189 |
transcript = get_transcript(youtube_url, YOUTUBE_API_KEY)
|
| 190 |
if not transcript:
|
| 191 |
return "Failed to fetch transcript. Try another video."
|
| 192 |
|
|
|
|
| 193 |
summarized_text = summarize_text_huggingface(transcript)
|
|
|
|
|
|
|
|
|
|
| 194 |
optimized_content = generate_optimized_content(OPENAI_API_KEY, summarized_text)
|
|
|
|
| 195 |
if optimized_content:
|
| 196 |
return json.dumps(optimized_content, indent=4)
|
| 197 |
else:
|
| 198 |
return "Failed to generate SEO content."
|
| 199 |
|
| 200 |
-
# Define
|
| 201 |
iface = gr.Interface(
|
| 202 |
fn=youtube_seo_pipeline,
|
| 203 |
inputs="text",
|
|
@@ -206,6 +222,6 @@ iface = gr.Interface(
|
|
| 206 |
description="Enter a YouTube video URL to fetch and optimize SEO content (title, description, tags, and keywords)."
|
| 207 |
)
|
| 208 |
|
| 209 |
-
#
|
| 210 |
if __name__ == "__main__":
|
| 211 |
-
iface.launch()
|
|
|
|
| 177 |
except Exception as e:
|
| 178 |
print(f"Error generating content: {e}")
|
| 179 |
return None
|
| 180 |
+
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
|
| 181 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 182 |
+
|
| 183 |
+
# Add all your functions like `extract_video_id()`, `get_transcript()`, etc.
|
| 184 |
+
|
| 185 |
+
# Gradio Function for YouTube SEO
|
| 186 |
def youtube_seo_pipeline(youtube_url):
|
| 187 |
+
print("Starting the SEO pipeline...") # Debugging line
|
| 188 |
+
|
| 189 |
if not YOUTUBE_API_KEY or not OPENAI_API_KEY:
|
| 190 |
return "API keys missing! Please check environment variables."
|
| 191 |
|
| 192 |
+
print("Extracting video ID...")
|
| 193 |
video_id = extract_video_id(youtube_url)
|
| 194 |
if not video_id:
|
| 195 |
return "Invalid YouTube URL."
|
| 196 |
|
| 197 |
+
print(f"Video ID: {video_id}")
|
| 198 |
+
|
| 199 |
+
print("Fetching transcript...")
|
| 200 |
transcript = get_transcript(youtube_url, YOUTUBE_API_KEY)
|
| 201 |
if not transcript:
|
| 202 |
return "Failed to fetch transcript. Try another video."
|
| 203 |
|
| 204 |
+
print("Summarizing transcript...")
|
| 205 |
summarized_text = summarize_text_huggingface(transcript)
|
| 206 |
+
print(f"Summarized Text: {summarized_text[:200]}...") # Show only the first 200 chars
|
| 207 |
+
|
| 208 |
+
print("Generating optimized content...")
|
| 209 |
optimized_content = generate_optimized_content(OPENAI_API_KEY, summarized_text)
|
| 210 |
+
|
| 211 |
if optimized_content:
|
| 212 |
return json.dumps(optimized_content, indent=4)
|
| 213 |
else:
|
| 214 |
return "Failed to generate SEO content."
|
| 215 |
|
| 216 |
+
# Define Gradio Interface
|
| 217 |
iface = gr.Interface(
|
| 218 |
fn=youtube_seo_pipeline,
|
| 219 |
inputs="text",
|
|
|
|
| 222 |
description="Enter a YouTube video URL to fetch and optimize SEO content (title, description, tags, and keywords)."
|
| 223 |
)
|
| 224 |
|
| 225 |
+
# Launch Gradio App
|
| 226 |
if __name__ == "__main__":
|
| 227 |
+
iface.launch()
|