nehapasricha94 commited on
Commit
8ed452a
1 Parent(s): 028e80e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -7,10 +7,14 @@ from transformers import pipeline
7
  import gradio as gr
8
  from sklearn.cluster import KMeans
9
  from colorsys import rgb_to_hsv
 
10
 
11
- # Emotion detection pipeline for text (if any text is included in assets)
12
  emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
13
 
 
 
 
14
  # Function to analyze colors in an image
15
  def analyze_colors(image):
16
  try:
@@ -117,8 +121,8 @@ def analyze_patterns(image):
117
  def compute_overall_result(color_emotions, stress_levels, pattern_analysis, pattern_stress):
118
  try:
119
  # Assigning weightage to different factors
120
- color_emotion_weight = 0.5 # 70% for color-based emotions and stress
121
- pattern_weight = 0.5 # 30% for pattern analysis
122
 
123
  # Determine the most common emotion from colors
124
  dominant_emotion = max(set(color_emotions), key=color_emotions.count)
@@ -153,6 +157,18 @@ def compute_overall_result(color_emotions, stress_levels, pattern_analysis, patt
153
  return f"Error computing overall result: {str(e)}"
154
 
155
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  # Main function to process image and analyze emotional expression
157
  def analyze_emotion_from_image(image):
158
  try:
 
7
  import gradio as gr
8
  from sklearn.cluster import KMeans
9
  from colorsys import rgb_to_hsv
10
+ from huggingface_hub import InferenceClient # Import InferenceClient for API calls
11
 
12
+ # Initialize the emotion detection pipeline for text (if any text is included in assets)
13
  emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
14
 
15
+ # Initialize the Hugging Face API client with your Space model ID
16
+ client = InferenceClient("nehapasricha94/LLaVA-image-analysis")
17
+
18
  # Function to analyze colors in an image
19
  def analyze_colors(image):
20
  try:
 
121
  def compute_overall_result(color_emotions, stress_levels, pattern_analysis, pattern_stress):
122
  try:
123
  # Assigning weightage to different factors
124
+ color_emotion_weight = 0.5 # 50% for color-based emotions and stress
125
+ pattern_weight = 0.5 # 50% for pattern analysis
126
 
127
  # Determine the most common emotion from colors
128
  dominant_emotion = max(set(color_emotions), key=color_emotions.count)
 
157
  return f"Error computing overall result: {str(e)}"
158
 
159
 
160
+ # Function to analyze emotions from a given text (if applicable)
161
+ def analyze_emotion_from_text(text):
162
+ try:
163
+ # Using the local emotion classifier
164
+ emotion_scores = emotion_classifier(text)
165
+ dominant_emotion = max(emotion_scores, key=lambda x: x['score'])
166
+ return f"Detected emotion from text: {dominant_emotion['label']} with score: {dominant_emotion['score']:.2f}"
167
+ except Exception as e:
168
+ print(f"Error analyzing emotion from text: {e}")
169
+ return "Error analyzing text emotion"
170
+
171
+
172
  # Main function to process image and analyze emotional expression
173
  def analyze_emotion_from_image(image):
174
  try: