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

validation is added to deal with insufficient data

Browse files
Files changed (1) hide show
  1. app.py +49 -47
app.py CHANGED
@@ -1,47 +1,49 @@
1
- # app.py
2
-
3
- import gradio as gr
4
- import google.generativeai as genai
5
- import os
6
-
7
- # Configure Google Gemini API
8
- genai.configure(api_key="AIzaSyDBGF5y7WqDB0SO7-UO6yjshiEZN3Hpt3g") # Replace with your API key
9
-
10
- # Function to get a response from the Google Gemini model
11
- def get_gemini_response(input_text):
12
- model = genai.GenerativeModel('gemini-1.5-flash')
13
-
14
- # Input prompt for extracting unarticulated needs and wants
15
- input_prompt = f"""
16
- From the following user story, extract the unarticulated needs and wants.
17
- User story: {input_text}
18
-
19
- Needs are the unspoken requirements or desires the person might not have expressed directly.
20
- Wants are the things the person wishes for but didn't explicitly say.
21
-
22
- Needs and Wants:
23
- """
24
-
25
- # Generate the content based on text input
26
- response = model.generate_content([input_text, input_prompt])
27
- return response.text
28
-
29
- # Gradio interface function
30
- def extract_needs_and_wants(user_story):
31
- try:
32
- return get_gemini_response(user_story)
33
- except Exception as e:
34
- return f"Error: {str(e)}"
35
-
36
- # Create the Gradio interface
37
- interface = gr.Interface(
38
- fn=extract_needs_and_wants,
39
- inputs="text",
40
- outputs="text",
41
- title="Unarticulated Needs & Wants Extractor",
42
- description="Enter a user story to extract the unarticulated needs and wants using the Gemini model.",
43
- examples=[["The user often speaks about wanting to improve their health but is hesitant to join a gym."]]
44
- )
45
-
46
- # Launch the Gradio app
47
- interface.launch()
 
 
 
1
+ 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)}"
37
+
38
+ # Create the Gradio interface
39
+ interface = gr.Interface(
40
+ fn=extract_needs_and_wants,
41
+ inputs="text",
42
+ outputs="text",
43
+ title="Unarticulated Needs & Wants Extractor",
44
+ description="Enter a detailed user story to extract the unarticulated needs and wants using the Gemini model.",
45
+ examples=[["The user often speaks about wanting to improve their health but is hesitant to join a gym."]]
46
+ )
47
+
48
+ # Launch the Gradio app
49
+ interface.launch()