Rahatara commited on
Commit
3d7f238
·
verified ·
1 Parent(s): e05482a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -29,6 +29,19 @@ def frame_capture(video_path, num_frames=5):
29
  vidObj.release()
30
  return frames
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # Function to generate text descriptions for frames or answer a specific question
33
  def analyze_video(video_path, user_question):
34
  frames = frame_capture(video_path)
@@ -58,15 +71,28 @@ def chat_interaction(video_path, chatbot, user_message):
58
 
59
  # Define Gradio interface
60
  video_input = gr.Video(label="Upload Video", autoplay=True)
61
- chatbot = gr.Chatbot(label="Video Analysis Chatbot")
62
- user_input = gr.Textbox(label="Ask something specific about the video", placeholder="E.g., Are there any cars in this video?")
63
 
64
- # Create Gradio app
65
- with gr.Blocks() as demo:
66
  with gr.Column():
67
- video_input.render()
68
- chatbot.render()
69
- user_input.render()
70
- user_input.submit(fn=chat_interaction, inputs=[video_input, chatbot, user_input], outputs=[user_input, chatbot])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  demo.launch()
 
29
  vidObj.release()
30
  return frames
31
 
32
+ # Function for railway defect analysis with a set prompt
33
+ def railway_defect_analysis(video_path):
34
+ frames = frame_capture(video_path)
35
+ images = [PIL.Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) for frame in frames]
36
+
37
+ prompt = "Describe any potential railway defects or issues visible in these video frames."
38
+ images_with_prompt = [prompt] + images
39
+
40
+ responses = model.generate_content(images_with_prompt)
41
+ descriptions = [response.text for response in responses]
42
+
43
+ return format_descriptions(descriptions)
44
+
45
  # Function to generate text descriptions for frames or answer a specific question
46
  def analyze_video(video_path, user_question):
47
  frames = frame_capture(video_path)
 
71
 
72
  # Define Gradio interface
73
  video_input = gr.Video(label="Upload Video", autoplay=True)
 
 
74
 
75
+ # Railway defect analysis tab
76
+ with gr.Blocks() as railway_tab:
77
  with gr.Column():
78
+ gr.Markdown("### Railway Defect Analysis")
79
+ railway_video_input = video_input.render()
80
+ defect_analysis_output = gr.Textbox(label="Defect Analysis")
81
+ analyze_button = gr.Button("Analyze for Railway Defects")
82
+ analyze_button.click(fn=railway_defect_analysis, inputs=railway_video_input, outputs=defect_analysis_output)
83
+
84
+ # Interactive chat tab
85
+ with gr.Blocks() as chat_tab:
86
+ with gr.Column():
87
+ gr.Markdown("### Interactive Chat Mode")
88
+ chat_video_input = video_input.render()
89
+ chatbot = gr.Chatbot(label="Video Analysis Chatbot")
90
+ user_input = gr.Textbox(label="Ask something specific about the video", placeholder="E.g., Are there any cars in this video?")
91
+ user_input.submit(fn=chat_interaction, inputs=[chat_video_input, chatbot, user_input], outputs=[user_input, chatbot])
92
+
93
+ # Combine the two tabs into a single interface
94
+ with gr.Blocks() as demo:
95
+ with gr.TabbedInterface([railway_tab, chat_tab], ["Railway Defect Analysis", "Interactive Chat"]):
96
+ pass
97
 
98
  demo.launch()