VPCSinfo commited on
Commit
cc4b72f
·
1 Parent(s): fd7a4e9

Add Gemini API key and model configuration to UI

Browse files
Files changed (3) hide show
  1. README.md +68 -0
  2. app.py +26 -7
  3. tool.py +10 -8
README.md CHANGED
@@ -11,4 +11,72 @@ tags:
11
  - tool
12
  ---
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
11
  - tool
12
  ---
13
 
14
+ # YouTube Transcript Summarizer and Blog Content Generator
15
+
16
+ This tool extracts transcripts from YouTube videos, summarizes them using Google's Gemini AI, generates relevant images using Hugging Face models, and creates a formatted DOCX document with the content.
17
+
18
+ ## Features
19
+
20
+ - Extract transcripts from YouTube videos with automatic language detection
21
+ - Summarize transcripts using Google's Gemini AI models
22
+ - Generate relevant images based on the summary content
23
+ - Create or update DOCX documents with the transcript, summary, and images
24
+ - Support for multiple languages (summarizes in the same language as the transcript)
25
+ - Configurable AI models and API keys directly from the UI
26
+
27
+ ## Setup and Usage
28
+
29
+ 1. **API Keys**:
30
+ - **Hugging Face API Key**: Required for image generation
31
+ - **Gemini API Key**: Required for transcript summarization
32
+ - Both keys can be entered directly in the UI
33
+
34
+ 2. **Model Configuration**:
35
+ - Select from different Gemini models:
36
+ - gemini-2.0-flash (default)
37
+ - gemini-1.5-pro
38
+ - gemini-1.5-flash
39
+
40
+ 3. **Input**:
41
+ - Enter a YouTube video URL
42
+ - Optionally provide an existing DOCX file to update
43
+
44
+ 4. **Output**:
45
+ - Extracted transcript
46
+ - Generated summary
47
+ - Generated image
48
+ - DOCX document with all content
49
+
50
+ ## Environment Variables
51
+
52
+ You can optionally set API keys in a `.env` file:
53
+
54
+ ```
55
+ HF_API_KEY=your_hugging_face_api_key
56
+ GEMINI_API_KEY=your_gemini_api_key
57
+ ```
58
+
59
+ ## Requirements
60
+
61
+ - Python 3.8+
62
+ - Required packages are listed in `requirements.txt`
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ # Clone the repository
68
+ git clone https://github.com/yourusername/tool-YoutubeTranscript-blog.git
69
+ cd tool-YoutubeTranscript-blog
70
+
71
+ # Create a virtual environment
72
+ python -m venv .venv
73
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
74
+
75
+ # Install dependencies
76
+ pip install -r requirements.txt
77
+
78
+ # Run the application
79
+ python app.py
80
+ ```
81
+
82
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -10,9 +10,13 @@ youtube_tool = YouTubeTranscriptExtractor()
10
  docx_tool = TranscriptToDocx()
11
  #summarizer_tool = TranscriptSummarizer()
12
 
13
- def process_youtube_video(video_url, hf_api_key, existing_docx_path=None):
14
  # Initialize tools
15
- summarizer_tool = TranscriptSummarizer(hf_api_key=hf_api_key)
 
 
 
 
16
 
17
  # Get video title
18
  from pytubefix import YouTube
@@ -86,15 +90,30 @@ with gr.Blocks() as demo:
86
  gr.Markdown("# YouTube Transcript Summarizer and Blog Content Generator")
87
  gr.Markdown("Enter a YouTube video URL and Hugging Face API Key to extract the transcript, summarize it, and generate blog content with an image and DOCX file. Optionally, you can provide an existing DOCX file to update.")
88
 
89
- # Check if Gemini API key is set
90
- gemini_api_key = os.getenv("GEMINI_API_KEY")
91
- if not gemini_api_key or gemini_api_key == "your_gemini_api_key_here":
92
- gr.Markdown("⚠️ **Warning**: Gemini API key is not set in the .env file. Please add your Gemini API key to the .env file to use the summarization feature.")
93
 
94
  with gr.Row():
95
  with gr.Column():
96
  video_url = gr.Textbox(label="YouTube Video URL")
 
 
 
97
  hf_api_key = gr.Textbox(label="Hugging Face API Key", type="password")
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  existing_docx = gr.File(label="Existing DOCX file (optional)", file_types=[".docx"])
99
  submit_btn = gr.Button("Process Video")
100
 
@@ -106,7 +125,7 @@ with gr.Blocks() as demo:
106
 
107
  submit_btn.click(
108
  fn=process_youtube_video,
109
- inputs=[video_url, hf_api_key, existing_docx],
110
  outputs=[transcript_output, summary_output, image_output, docx_output]
111
  )
112
 
 
10
  docx_tool = TranscriptToDocx()
11
  #summarizer_tool = TranscriptSummarizer()
12
 
13
+ def process_youtube_video(video_url, hf_api_key, gemini_api_key, model_name, existing_docx_path=None):
14
  # Initialize tools
15
+ summarizer_tool = TranscriptSummarizer(
16
+ hf_api_key=hf_api_key,
17
+ gemini_api_key=gemini_api_key,
18
+ model_name=model_name
19
+ )
20
 
21
  # Get video title
22
  from pytubefix import YouTube
 
90
  gr.Markdown("# YouTube Transcript Summarizer and Blog Content Generator")
91
  gr.Markdown("Enter a YouTube video URL and Hugging Face API Key to extract the transcript, summarize it, and generate blog content with an image and DOCX file. Optionally, you can provide an existing DOCX file to update.")
92
 
93
+ # Information about API keys
94
+ gr.Markdown("### API Keys and Model Configuration")
95
+ gr.Markdown("You need to provide both a Hugging Face API key (for image generation) and a Gemini API key (for summarization). You can now enter your Gemini API key directly in the UI or set it in the .env file.")
 
96
 
97
  with gr.Row():
98
  with gr.Column():
99
  video_url = gr.Textbox(label="YouTube Video URL")
100
+
101
+ # API Keys
102
+ gr.Markdown("#### API Keys")
103
  hf_api_key = gr.Textbox(label="Hugging Face API Key", type="password")
104
+ gemini_api_key = gr.Textbox(
105
+ label="Gemini API Key",
106
+ type="password",
107
+ value=os.getenv("GEMINI_API_KEY", "")
108
+ )
109
+
110
+ # Model Selection
111
+ model_name = gr.Dropdown(
112
+ label="Gemini Model",
113
+ choices=["gemini-2.0-flash", "gemini-1.5-pro", "gemini-1.5-flash"],
114
+ value="gemini-2.0-flash"
115
+ )
116
+
117
  existing_docx = gr.File(label="Existing DOCX file (optional)", file_types=[".docx"])
118
  submit_btn = gr.Button("Process Video")
119
 
 
125
 
126
  submit_btn.click(
127
  fn=process_youtube_video,
128
+ inputs=[video_url, hf_api_key, gemini_api_key, model_name, existing_docx],
129
  outputs=[transcript_output, summary_output, image_output, docx_output]
130
  )
131
 
tool.py CHANGED
@@ -24,15 +24,17 @@ class TranscriptSummarizer(Tool):
24
  }
25
  output_type = "string"
26
 
27
- def __init__(self, *args, hf_api_key: str = None, **kwargs):
28
  super().__init__(*args, **kwargs)
29
- # Get Gemini API key from environment variables
30
- gemini_api_key = os.getenv("GEMINI_API_KEY")
31
- if gemini_api_key:
 
 
32
  # Configure the Gemini API
33
- genai.configure(api_key=gemini_api_key)
34
- # Set up the model
35
- self.gemini_model = genai.GenerativeModel('gemini-2.0-flash')
36
  else:
37
  self.gemini_model = None
38
 
@@ -106,7 +108,7 @@ class TranscriptSummarizer(Tool):
106
  return "Hugging Face API key is required for image generation. Please provide it in the input field."
107
 
108
  if not self.gemini_model:
109
- return "Gemini API key is required for summarization. Please add it to your .env file."
110
 
111
  transcript_length = len(transcript)
112
 
 
24
  }
25
  output_type = "string"
26
 
27
+ def __init__(self, *args, hf_api_key: str = None, gemini_api_key: str = None, model_name: str = 'gemini-2.0-flash', **kwargs):
28
  super().__init__(*args, **kwargs)
29
+ # Use provided Gemini API key or get from environment variables
30
+ self.gemini_api_key = gemini_api_key or os.getenv("GEMINI_API_KEY")
31
+ self.model_name = model_name
32
+
33
+ if self.gemini_api_key:
34
  # Configure the Gemini API
35
+ genai.configure(api_key=self.gemini_api_key)
36
+ # Set up the model with the specified model name
37
+ self.gemini_model = genai.GenerativeModel(self.model_name)
38
  else:
39
  self.gemini_model = None
40
 
 
108
  return "Hugging Face API key is required for image generation. Please provide it in the input field."
109
 
110
  if not self.gemini_model:
111
+ return "Gemini API key is required for summarization. Please provide it in the input field."
112
 
113
  transcript_length = len(transcript)
114