import gradio as gr import google.generativeai as genai # Configure Google Gemini API genai.configure(api_key) # Replace with your actual API key # Function to get a response from the Google Gemini model def get_gemini_response(input_text): # Check if the 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." # Concise prompt to limit output to essential insights input_prompt = f""" Based on the user story "{input_text}", briefly extract any unarticulated needs and wants. Only provide essential needs and wants directly relevant to the given story. Do not speculate or over-extrapolate. Needs and Wants: """ # Generate the content based on text input model = genai.GenerativeModel('gemini-1.5-flash') response = model.generate_content([input_text, input_prompt]) return response.text # Gradio interface function def extract_needs_and_wants(user_story): try: return get_gemini_response(user_story) except Exception as e: return f"Error: {str(e)}" # Create the Gradio interface import gradio as gr interface = gr.Interface( fn=extract_needs_and_wants, inputs="text", outputs="text", title="Unarticulated Needs & Wants Extractor", description="**Author:** VictorDaniel\n\nEnter a detailed user story 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."]] ) interface.launch() # Launch the Gradio app interface.launch()