import gradio as gr from transformers import GPT2Tokenizer, GPT2LMHeadModel import cv2 import tempfile import os # Load the tokenizer and model tokenizer = GPT2Tokenizer.from_pretrained('gpt2') model = GPT2LMHeadModel.from_pretrained('gpt2') # Function to generate responses from the model def generate_response(question): inputs = tokenizer.encode(question, return_tensors='pt') outputs = model.generate(inputs, max_length=100, num_return_sequences=1) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response # Function to process video and extract text question def process_video(video_path): # Placeholder for video processing and speech-to-text conversion # Currently returning a dummy question for simplicity question = "What are your strengths and weaknesses?" return question # Main function to handle video input and generate text response def video_interview(video): with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_file: temp_file.write(video.read()) temp_video_path = temp_file.name question = process_video(temp_video_path) response = generate_response(question) os.remove(temp_video_path) return response # Gradio interface iface = gr.Interface( fn=video_interview, inputs=gr.Video(), outputs="text", title="Mock Interviewee Video Bot", description="Upload a video question or use your webcam to ask a question and get a simulated interview response." ) if __name__ == "__main__": iface.launch()