Dy commited on
Commit
00dc332
1 Parent(s): 396d793

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
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
- f= open("temp.txt","w+")
43
- f.write(get_captions(youtube_url))
44
- f.close()
45
-
46
- loader = TextLoader("temp.txt")
47
-
48
- index = VectorstoreIndexCreator().from_loaders([loader])
49
- os.remove("temp.txt")
50
-
51
- query = user_question
52
- answer = index.query(query)
 
 
 
 
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