Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,10 @@ from transformers import pipeline
|
|
| 9 |
|
| 10 |
API_KEY = os.getenv("API_KEY")
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
headers = {"Authorization": "Bearer "+ API_KEY+""}
|
| 14 |
|
| 15 |
reader = easyocr.Reader(['en'], gpu=False)
|
|
@@ -22,7 +25,7 @@ def query(image):
|
|
| 22 |
_, buffer = cv2.imencode('.jpg', image_data)
|
| 23 |
binary_data = buffer.tobytes()
|
| 24 |
|
| 25 |
-
response = requests.post(
|
| 26 |
result = {item['label']: item['score'] for item in response.json()}
|
| 27 |
|
| 28 |
return result
|
|
@@ -42,12 +45,11 @@ def text_extraction(image):
|
|
| 42 |
return image, text_content, facial_data
|
| 43 |
|
| 44 |
def analyze_sentiment(text):
|
| 45 |
-
results =
|
| 46 |
-
sentiment_results = {result['label']: result['score'] for result in results}
|
| 47 |
return sentiment_results
|
| 48 |
|
| 49 |
def get_sentiment_emoji(sentiment):
|
| 50 |
-
# Define the emojis corresponding to each sentiment
|
| 51 |
emoji_mapping = {
|
| 52 |
"disappointment": "π",
|
| 53 |
"sadness": "π’",
|
|
@@ -182,15 +184,17 @@ with block:
|
|
| 182 |
gr.Textbox(label="Text Content")
|
| 183 |
|
| 184 |
output_text_sentiment = gr.Textbox(label="Text Sentiment")
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
sentiment_option = gr.Radio(choices=["Sentiment Only", "Sentiment + Score"], label="Select an option")
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
|
| 196 |
btn = gr.Button("Run")
|
|
|
|
| 9 |
|
| 10 |
API_KEY = os.getenv("API_KEY")
|
| 11 |
|
| 12 |
+
IMAGE_API_URL = "https://api-inference.huggingface.co/models/dima806/facial_emotions_image_detection"
|
| 13 |
+
headers = {"Authorization": "Bearer "+ API_KEY+""}
|
| 14 |
+
|
| 15 |
+
EMOTIONS_API_URL = "https://api-inference.huggingface.co/models/SamLowe/roberta-base-go_emotions"
|
| 16 |
headers = {"Authorization": "Bearer "+ API_KEY+""}
|
| 17 |
|
| 18 |
reader = easyocr.Reader(['en'], gpu=False)
|
|
|
|
| 25 |
_, buffer = cv2.imencode('.jpg', image_data)
|
| 26 |
binary_data = buffer.tobytes()
|
| 27 |
|
| 28 |
+
response = requests.post(IMAGE_API_URL, headers=headers, data=binary_data)
|
| 29 |
result = {item['label']: item['score'] for item in response.json()}
|
| 30 |
|
| 31 |
return result
|
|
|
|
| 45 |
return image, text_content, facial_data
|
| 46 |
|
| 47 |
def analyze_sentiment(text):
|
| 48 |
+
results = requests.post(EMOTIONS_API_URL, headers=headers, json=text)
|
| 49 |
+
sentiment_results = {result['label']: result['score'] for result in results.json()}
|
| 50 |
return sentiment_results
|
| 51 |
|
| 52 |
def get_sentiment_emoji(sentiment):
|
|
|
|
| 53 |
emoji_mapping = {
|
| 54 |
"disappointment": "π",
|
| 55 |
"sadness": "π’",
|
|
|
|
| 184 |
gr.Textbox(label="Text Content")
|
| 185 |
|
| 186 |
output_text_sentiment = gr.Textbox(label="Text Sentiment")
|
| 187 |
+
|
| 188 |
+
with gr.Blocks():
|
| 189 |
+
with gr.Row():
|
| 190 |
+
audio = gr.Audio(label="Input Audio", show_label=False, type="filepath")
|
|
|
|
| 191 |
|
| 192 |
+
with gr.Row():
|
| 193 |
+
sentiment_option = gr.Radio(choices=["Sentiment Only", "Sentiment + Score"], label="Select an option")
|
| 194 |
+
|
| 195 |
+
lang_str = gr.Textbox(label="Language")
|
| 196 |
+
text = gr.Textbox(label="Transcription")
|
| 197 |
+
sentiment_output = gr.Textbox(label="Audio Text Sentiment")
|
| 198 |
|
| 199 |
|
| 200 |
btn = gr.Button("Run")
|