Spaces:
Running
Running
import gradio as gr | |
import google.generativeai as genai | |
# Configure Google Gemini API | |
genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # Replace with your API key | |
# Function to get a response from the Google Gemini model | |
def get_gemini_response(input_text): | |
model = genai.GenerativeModel('gemini-1.5-flash') | |
# Input prompt for extracting unarticulated needs and wants | |
input_prompt = f""" | |
From the following user story, extract the unarticulated needs and wants. | |
User story: {input_text} | |
Needs are the unspoken requirements or desires the person might not have expressed directly. | |
Wants are the things the person wishes for but didn't explicitly say. | |
Needs and Wants: | |
""" | |
# Generate the content based on text input | |
response = model.generate_content([input_text, input_prompt]) | |
return response.text | |
# Enhanced Gradio interface function with input validation | |
def extract_needs_and_wants(user_story): | |
# Check if the input story is adequate (e.g., at least 20 characters or more than a few words) | |
if len(user_story.strip()) < 20 or len(user_story.split()) < 5: | |
return "Please provide a detailed user story with sufficient content for analysis." | |
try: | |
# Process the input if it meets the criteria | |
return get_gemini_response(user_story) | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# Create the Gradio interface | |
interface = gr.Interface( | |
fn=extract_needs_and_wants, | |
inputs="text", | |
outputs="text", | |
title="Unarticulated Needs & Wants Extractor", | |
description="Enter a detailed user story to extract the unarticulated needs and wants using the Gemini model.", | |
examples=[["The user often speaks about wanting to improve their health but is hesitant to join a gym."]] | |
) | |
# Launch the Gradio app | |
interface.launch() | |