Update app.py
Browse files
app.py
CHANGED
|
@@ -67,7 +67,7 @@ def segment_text(segments: list[dict]) -> list[str]:
|
|
| 67 |
|
| 68 |
def summarize_text(text: str) -> str:
|
| 69 |
"""
|
| 70 |
-
Summarize a chunk of transcript via GPT
|
| 71 |
"""
|
| 72 |
prompt = f"Summarize the following lecture segment in 2-3 sentences:\n\n{text}"
|
| 73 |
response = openai.ChatCompletion.create(
|
|
@@ -100,10 +100,11 @@ def extract_frame(video_path: str, timestamp: str, output_path: str) -> None:
|
|
| 100 |
subprocess.run(cmd, check=True)
|
| 101 |
|
| 102 |
|
| 103 |
-
def run_pipeline(video_file: str) -> list[dict]:
|
| 104 |
"""
|
| 105 |
Execute the full pipeline and return timeline as a list of dicts.
|
| 106 |
"""
|
|
|
|
| 107 |
chunks = chunk_video(video_file)
|
| 108 |
all_segments = []
|
| 109 |
for chunk in chunks:
|
|
@@ -139,17 +140,13 @@ def run_pipeline(video_file: str) -> list[dict]:
|
|
| 139 |
# Gradio interface for Hugging Face Spaces
|
| 140 |
demo = gr.Blocks()
|
| 141 |
with demo:
|
| 142 |
-
gr.Markdown("# Lecture Capture AI Pipeline\
|
|
|
|
| 143 |
video_input = gr.Video(label="Lecture Video File")
|
| 144 |
run_button = gr.Button("Process Video")
|
| 145 |
output = gr.JSON(label="Generated Timeline")
|
| 146 |
|
| 147 |
-
run_button.click(fn=
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|
| 150 |
-
# Prompt for API key if not set in environment
|
| 151 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
| 152 |
-
if not api_key:
|
| 153 |
-
api_key = input("Enter your OpenAI API key: ")
|
| 154 |
-
openai.api_key = api_key
|
| 155 |
demo.launch()
|
|
|
|
| 67 |
|
| 68 |
def summarize_text(text: str) -> str:
|
| 69 |
"""
|
| 70 |
+
Summarize a chunk of transcript via GPT.
|
| 71 |
"""
|
| 72 |
prompt = f"Summarize the following lecture segment in 2-3 sentences:\n\n{text}"
|
| 73 |
response = openai.ChatCompletion.create(
|
|
|
|
| 100 |
subprocess.run(cmd, check=True)
|
| 101 |
|
| 102 |
|
| 103 |
+
def run_pipeline(api_key: str, video_file: str) -> list[dict]:
|
| 104 |
"""
|
| 105 |
Execute the full pipeline and return timeline as a list of dicts.
|
| 106 |
"""
|
| 107 |
+
openai.api_key = api_key
|
| 108 |
chunks = chunk_video(video_file)
|
| 109 |
all_segments = []
|
| 110 |
for chunk in chunks:
|
|
|
|
| 140 |
# Gradio interface for Hugging Face Spaces
|
| 141 |
demo = gr.Blocks()
|
| 142 |
with demo:
|
| 143 |
+
gr.Markdown("# Lecture Capture AI Pipeline\nEnter your OpenAI API key and upload a lecture video to generate a summarized timeline.")
|
| 144 |
+
api_key_input = gr.Textbox(label="OpenAI API Key", type="password", placeholder="sk-...", lines=1)
|
| 145 |
video_input = gr.Video(label="Lecture Video File")
|
| 146 |
run_button = gr.Button("Process Video")
|
| 147 |
output = gr.JSON(label="Generated Timeline")
|
| 148 |
|
| 149 |
+
run_button.click(fn=run_pipeline, inputs=[api_key_input, video_input], outputs=output)
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
demo.launch()
|