Spaces:
Runtime error
Runtime error
wendru18
commited on
Commit
·
3e7095a
1
Parent(s):
3cc6acd
added readme
Browse files
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Ask Youtube Gpt
|
3 |
+
emoji: 📺
|
4 |
+
colorFrom: white
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.28.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
# Ask Youtube GPT
|
13 |
+
|
14 |
+
Ask YouTube GPT allows you to ask questions about a set of YouTube Videos using Topic Segmentation, Universal Sentence Encoding, and Open AI.
|
app.py
CHANGED
@@ -9,6 +9,7 @@ import tiktoken
|
|
9 |
import openai
|
10 |
import json
|
11 |
import re
|
|
|
12 |
|
13 |
tt = TextTilingTokenizer()
|
14 |
searcher = SemanticSearch()
|
@@ -20,8 +21,8 @@ title_counter = {}
|
|
20 |
titles_to_urls = {}
|
21 |
|
22 |
def set_openai_key(key):
|
23 |
-
if key == "":
|
24 |
-
|
25 |
openai.api_key = key
|
26 |
|
27 |
def get_youtube_data(url):
|
@@ -120,13 +121,12 @@ def refencify(text):
|
|
120 |
end_seconds = to_seconds(end_timestamp)
|
121 |
|
122 |
video_iframe = f'''<iframe
|
123 |
-
width="
|
124 |
height="240"
|
125 |
-
src="{url.replace("watch?v=", "embed/")}?start={start_seconds}&end={end_seconds}"
|
126 |
frameborder="0"
|
127 |
-
allow="autoplay; encrypted-media"
|
128 |
allowfullscreen
|
129 |
-
controls="0"
|
130 |
>
|
131 |
</iframe>'''
|
132 |
|
@@ -179,7 +179,7 @@ def generate_answer(question, model, token_budget, temperature):
|
|
179 |
)
|
180 |
|
181 |
response_message = response["choices"][0]["message"]["content"]
|
182 |
-
|
183 |
return response_message, references
|
184 |
|
185 |
def add_to_dict(title, url):
|
@@ -238,18 +238,18 @@ title = "Ask YouTube GPT 📺"
|
|
238 |
with gr.Blocks() as demo:
|
239 |
|
240 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
241 |
-
gr.Markdown(f'Ask YouTube GPT allows you to ask questions about a set of
|
242 |
|
243 |
with gr.Row():
|
244 |
|
245 |
with gr.Group():
|
246 |
|
247 |
-
openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
|
248 |
|
249 |
# Allow the user to input multiple links, adding a textbox for each
|
250 |
-
urls_text = gr.Textbox(lines=5, label="Enter the links to the YouTube videos you want to search (one per line):", placeholder="https://www.youtube.com/watch?v
|
251 |
|
252 |
-
question = gr.Textbox(label='Enter your question here')
|
253 |
|
254 |
with gr.Accordion("Advanced Settings", open=False):
|
255 |
split_by_topic = gr.Checkbox(label="Split segments by topic", value=True, info="Whether the video transcripts are to be segmented by topic or by word count. Topically-coherent segments may be more useful for question answering, but results in a slower response time, especially for lengthy videos.")
|
|
|
9 |
import openai
|
10 |
import json
|
11 |
import re
|
12 |
+
import os
|
13 |
|
14 |
tt = TextTilingTokenizer()
|
15 |
searcher = SemanticSearch()
|
|
|
21 |
titles_to_urls = {}
|
22 |
|
23 |
def set_openai_key(key):
|
24 |
+
if key == "env":
|
25 |
+
key = os.environ.get("OPENAI_API_KEY")
|
26 |
openai.api_key = key
|
27 |
|
28 |
def get_youtube_data(url):
|
|
|
121 |
end_seconds = to_seconds(end_timestamp)
|
122 |
|
123 |
video_iframe = f'''<iframe
|
124 |
+
width="400"
|
125 |
height="240"
|
126 |
+
src="{url.replace("watch?v=", "embed/")}?start={start_seconds}&end={end_seconds}&controls=0"
|
127 |
frameborder="0"
|
128 |
+
allow="accelerometer; autoplay; modestbranding; encrypted-media; gyroscope; picture-in-picture"
|
129 |
allowfullscreen
|
|
|
130 |
>
|
131 |
</iframe>'''
|
132 |
|
|
|
179 |
)
|
180 |
|
181 |
response_message = response["choices"][0]["message"]["content"]
|
182 |
+
|
183 |
return response_message, references
|
184 |
|
185 |
def add_to_dict(title, url):
|
|
|
238 |
with gr.Blocks() as demo:
|
239 |
|
240 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
241 |
+
gr.Markdown(f'Ask YouTube GPT allows you to ask questions about a set of YouTube Videos using Topic Segmentation, Universal Sentence Encoding, and Open AI. The returned response cites the video title, author and timestamp in square brackets where the information is located, adding credibility to the responses and helping you locate incorrect information. If you need one, get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a>.</p>')
|
242 |
|
243 |
with gr.Row():
|
244 |
|
245 |
with gr.Group():
|
246 |
|
247 |
+
openAI_key=gr.Textbox(label='Enter your OpenAI API key here:')
|
248 |
|
249 |
# Allow the user to input multiple links, adding a textbox for each
|
250 |
+
urls_text = gr.Textbox(lines=5, label="Enter the links to the YouTube videos you want to search (one per line):", placeholder="https://www.youtube.com/watch?v=...")
|
251 |
|
252 |
+
question = gr.Textbox(label='Enter your question here:')
|
253 |
|
254 |
with gr.Accordion("Advanced Settings", open=False):
|
255 |
split_by_topic = gr.Checkbox(label="Split segments by topic", value=True, info="Whether the video transcripts are to be segmented by topic or by word count. Topically-coherent segments may be more useful for question answering, but results in a slower response time, especially for lengthy videos.")
|