deepaksarika01 commited on
Commit
6f6b132
·
1 Parent(s): 7cf68b3

Add options to add video ID

Browse files
Files changed (1) hide show
  1. model.py +62 -9
model.py CHANGED
@@ -7,6 +7,7 @@ from transformers import (
7
  pipeline,
8
  GenerationConfig
9
  )
 
10
 
11
  class lamini:
12
  def __init__(self):
@@ -114,15 +115,67 @@ class qa_template:
114
  _type_: _description_
115
  """
116
  import gradio as gr
 
117
 
118
  def interface(msg, history):
119
  res = self.qa_inf.run(msg)
120
- return str(res)
121
-
122
- ui = gr.ChatInterface(
123
- fn=interface,
124
- examples=["What is the video about?", "key points of the video"],
125
- title=f"Question Mode - {title}",
126
- )
127
-
128
- ui.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  pipeline,
8
  GenerationConfig
9
  )
10
+ from textwrap import dedent
11
 
12
  class lamini:
13
  def __init__(self):
 
115
  _type_: _description_
116
  """
117
  import gradio as gr
118
+ load = self.load
119
 
120
  def interface(msg, history):
121
  res = self.qa_inf.run(msg)
122
+ history.append((msg, res))
123
+ return "", history
124
+
125
+ def reload(video_id):
126
+ from utils import getSubsText
127
+ print(f"Setting up {video_id}")
128
+ subs = getSubsText(video_id)
129
+ _ = load(subs)
130
+
131
+ with gr.Blocks() as demo:
132
+ with gr.Column():
133
+ gr.Markdown(dedent(f"""
134
+ # video to QA
135
+ A test implementation to use vectorstres and mini llms to create
136
+ a question answer chatbot interface for _youtube videos_
137
+ """))
138
+ chatbot = gr.Chatbot()
139
+ with gr.Row():
140
+ with gr.Column():
141
+ videoId = gr.Textbox(label="Video ID", placeholder="Enter video ID here")
142
+ msg = gr.Textbox(label="Question Box" , placeholder="Enter your question here")
143
+ clear = gr.ClearButton([msg, videoId, chatbot])
144
+
145
+ gr.Markdown(
146
+ dedent("""
147
+
148
+ ## Getting started
149
+ to start up you need to enter the video ID of youtube video first
150
+
151
+ Get a youtube video which has English dialog
152
+ > ex: https://www.youtube.com/watch?v=BsnCpESUEqM
153
+
154
+ in this `BsnCpESUEqM` is the video ID
155
+
156
+ ```
157
+ https://www.youtube.com/watch?v=BsnCpESUEqM
158
+ ^^^^^^^^^^^
159
+ video_id
160
+ ```
161
+ > in url paramets are seperated by `?` and for video id its `?v`
162
+
163
+ copy-paste the video id to the textbox and press return/enter and wait ~5 seconds to fetch video information
164
+
165
+ ---
166
+
167
+ Now in the Question Box _box_/feild start typing the quesions and press return/enter to send to llm
168
+ """)
169
+ )
170
+ msg.submit(interface, [msg, chatbot], [msg, chatbot])
171
+ videoId.submit(reload, [videoId])
172
+
173
+
174
+ # ui = gr.ChatInterface(
175
+ # fn=interface,
176
+ # examples=["What is the video about?", "key points of the video"],
177
+ # title=f"Question Mode - {title}",
178
+ # )
179
+
180
+ # ui.launch()
181
+ demo.launch()