SenseMakingTool / app.py
Victor Daniel
Validation is added to deal with speculations.
d5264f2 verified
raw
history blame
1.64 kB
import gradio as gr
import google.generativeai as genai
# Configure Google Gemini API
genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # 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
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()