Spaces:
Sleeping
Sleeping
Dy
commited on
Commit
•
00dc332
1
Parent(s):
396d793
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ from langchain.indexes import VectorstoreIndexCreator
|
|
8 |
|
9 |
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
|
10 |
|
|
|
|
|
11 |
def get_video_id(url):
|
12 |
video_id = None
|
13 |
if 'youtu.be' in url:
|
@@ -38,18 +40,22 @@ def get_captions(url):
|
|
38 |
def answer_question(youtube_url, user_question):
|
39 |
# You can implement your logic here to process the video, transcribe it, and answer the user question.
|
40 |
# For now, let's return the user question as output.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
return answer
|
55 |
|
|
|
8 |
|
9 |
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
|
10 |
|
11 |
+
previous_youtube_url = None
|
12 |
+
|
13 |
def get_video_id(url):
|
14 |
video_id = None
|
15 |
if 'youtu.be' in url:
|
|
|
40 |
def answer_question(youtube_url, user_question):
|
41 |
# You can implement your logic here to process the video, transcribe it, and answer the user question.
|
42 |
# For now, let's return the user question as output.
|
43 |
+
global previous_youtube_url
|
44 |
+
if previous_youtube_url == youtube_url:
|
45 |
+
index = VectorstoreIndexCreator().from_loaders([loader])
|
46 |
+
query = user_question
|
47 |
+
answer = index.query(query)
|
48 |
+
else:
|
49 |
+
f= open("temp.txt","w+")
|
50 |
+
f.write(get_captions(youtube_url))
|
51 |
+
f.close()
|
52 |
+
loader = TextLoader("temp.txt")
|
53 |
+
|
54 |
+
index = VectorstoreIndexCreator().from_loaders([loader])
|
55 |
+
os.remove("temp.txt")
|
56 |
+
|
57 |
+
query = user_question
|
58 |
+
answer = index.query(query)
|
59 |
|
60 |
return answer
|
61 |
|