Victor Daniel commited on
Commit
d5264f2
1 Parent(s): b2af484

Validation is added to deal with speculations.

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -2,35 +2,31 @@ import gradio as gr
2
  import google.generativeai as genai
3
 
4
  # Configure Google Gemini API
5
- genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # Replace with your API key
6
 
7
  # Function to get a response from the Google Gemini model
8
  def get_gemini_response(input_text):
9
- model = genai.GenerativeModel('gemini-1.5-flash')
 
 
10
 
11
- # Input prompt for extracting unarticulated needs and wants
12
  input_prompt = f"""
13
- From the following user story, extract the unarticulated needs and wants.
14
- User story: {input_text}
15
 
16
- Needs are the unspoken requirements or desires the person might not have expressed directly.
17
- Wants are the things the person wishes for but didn't explicitly say.
18
 
19
  Needs and Wants:
20
  """
21
 
22
  # Generate the content based on text input
 
23
  response = model.generate_content([input_text, input_prompt])
24
  return response.text
25
 
26
- # Enhanced Gradio interface function with input validation
27
  def extract_needs_and_wants(user_story):
28
- # Check if the input story is adequate (e.g., at least 20 characters or more than a few words)
29
- if len(user_story.strip()) < 20 or len(user_story.split()) < 5:
30
- return "Please provide a detailed user story with sufficient content for analysis."
31
-
32
  try:
33
- # Process the input if it meets the criteria
34
  return get_gemini_response(user_story)
35
  except Exception as e:
36
  return f"Error: {str(e)}"
 
2
  import google.generativeai as genai
3
 
4
  # Configure Google Gemini API
5
+ genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # Replace with your actual API key
6
 
7
  # Function to get a response from the Google Gemini model
8
  def get_gemini_response(input_text):
9
+ # Check if the input is detailed enough
10
+ if len(input_text.split()) < 10:
11
+ return "Please provide a more detailed user story to help generate relevant needs and wants."
12
 
13
+ # Concise prompt to limit output to essential insights
14
  input_prompt = f"""
15
+ Based on the user story "{input_text}", briefly extract any unarticulated needs and wants.
 
16
 
17
+ Only provide essential needs and wants directly relevant to the given story. Do not speculate or over-extrapolate.
 
18
 
19
  Needs and Wants:
20
  """
21
 
22
  # Generate the content based on text input
23
+ model = genai.GenerativeModel('gemini-1.5-flash')
24
  response = model.generate_content([input_text, input_prompt])
25
  return response.text
26
 
27
+ # Gradio interface function
28
  def extract_needs_and_wants(user_story):
 
 
 
 
29
  try:
 
30
  return get_gemini_response(user_story)
31
  except Exception as e:
32
  return f"Error: {str(e)}"