Spaces:
Runtime error
Runtime error
VictorDanielG
commited on
Commit
•
091d8d3
1
Parent(s):
31e6e70
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|