#Praise Jesus! import gradio as gr import google.generativeai as genai from transformers import pipeline import docx2txt import os genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # Whisper model for audio transcription whisper_model = pipeline("automatic-speech-recognition", model="openai/whisper-large") # Function to generate response using Google Gemini model def get_gemini_response(input_text): # Ensure input is detailed enough if len(input_text.split()) < 10: return "Please provide a more detailed user story to help generate relevant needs and wants." # Define the prompt input_prompt = f""" Based on the user story "{input_text}", extract any unarticulated needs and wants. Only provide essential needs and wants directly relevant to the given story. Do not speculate or over-extrapolate. """ # Generate the response response = genai.GenerativeModel('gemini-1.5-flash').generate_content(input_prompt) return response.text # Main processing function for Gradio interface def process_input(user_story=None, user_audio=None, user_file=None): # Process audio input if provided if user_audio: transcription = whisper_model(user_audio)["text"] user_story = transcription # Process file input if provided and if text is empty if user_file and not user_story: user_story = docx2txt.process(user_file) # Ensure there's text to process if not user_story: return "Please provide a user story, an audio file, or upload a Word file." # Generate response with Google Gemini gemini_response = get_gemini_response(user_story) return f"Gemini Output:\n{gemini_response}" # Custom CSS styling for a colorful interface custom_css = """ .gradio-container { background-color: #f2f6ff; color: #333333; font-family: Arial, sans-serif; } .gr-button { background-color: #1e90ff; color: white; font-weight: bold; border-radius: 5px; padding: 8px 12px; } .gr-input, .gr-output { border-color: #1e90ff; } .gradio-block h1, .gradio-block h2 { color: #003366; } """ # Gradio interface with improved look and feel interface = gr.Interface( fn=process_input, inputs=[ gr.Textbox(label="User Story (Text Input)", placeholder="Enter your user story here...", lines=5), gr.Audio(type="filepath", label="User Story (Audio Input)"), gr.File(label="Upload Word File (.docx)") ], outputs="text", title="🌟 Multimodal Needs & Wants Extractor 🌟", description="**Author:** Victor Daniel\n\nEnter a detailed user story or upload an audio/Word file to extract the unarticulated needs and wants.", examples=[ ["The user often speaks about wanting to improve their health but is hesitant to join a gym."] ], css=custom_css, theme="huggingface" ) # Launch the Gradio app with custom CSS for styling interface.launch()