lochn commited on
Commit
4df2de5
·
verified ·
1 Parent(s): e28ac00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
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(
@@ -136,23 +136,20 @@ def run_pipeline(video_file: str) -> list[dict]:
136
  })
137
  return timeline
138
 
139
-
140
- def process_video(api_key: str, video_path: str) -> list[dict]:
141
- """
142
- Gradio wrapper: sets API key and runs pipeline on uploaded video.
143
- """
144
- openai.api_key = api_key
145
- return run_pipeline(video_path)
146
-
147
  # Gradio interface for Hugging Face Spaces
148
- with gr.Blocks() as demo:
149
- gr.Markdown("# Lecture Capture AI Pipeline\nEnter your OpenAI API key and upload a lecture video to generate a summarized timeline.")
150
- api_key_input = gr.Textbox(label="OpenAI API Key", type="password", placeholder="sk-...", lines=1)
151
  video_input = gr.Video(label="Lecture Video File")
152
  run_button = gr.Button("Process Video")
153
  output = gr.JSON(label="Generated Timeline")
154
 
155
- run_button.click(fn=process_video, inputs=[api_key_input, video_input], outputs=output)
156
 
157
  if __name__ == "__main__":
158
- demo.launch()
 
 
 
 
 
 
67
 
68
  def summarize_text(text: str) -> str:
69
  """
70
+ Summarize a chunk of transcript via GPT-4.
71
  """
72
  prompt = f"Summarize the following lecture segment in 2-3 sentences:\n\n{text}"
73
  response = openai.ChatCompletion.create(
 
136
  })
137
  return timeline
138
 
 
 
 
 
 
 
 
 
139
  # Gradio interface for Hugging Face Spaces
140
+ demo = gr.Blocks()
141
+ with demo:
142
+ gr.Markdown("# Lecture Capture AI Pipeline\nUpload a lecture video to generate a summarized timeline.")
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=lambda video_path: run_pipeline(video_path), inputs=video_input, outputs=output)
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()