Spaces:
Build error
Build error
make the labels visible instead of just a number oh and add a cute emoji!
Browse files
app.py
CHANGED
|
@@ -14,12 +14,21 @@ ld_client = LDClient(Config(ld_sdk_key))
|
|
| 14 |
def get_model_config():
|
| 15 |
flag_key = "swap-sentiment-models" # Replace with your flag key
|
| 16 |
# Create context using Context builder
|
| 17 |
-
context = Context.builder("context-key-123abc").name("
|
| 18 |
flag_variation = ld_client.variation(flag_key, context, default={})
|
| 19 |
|
| 20 |
model_id = flag_variation.get("modelID", "distilbert-base-uncased")
|
| 21 |
return model_id
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Streamlit app
|
| 25 |
st.title("Sentiment Analysis Demo with AI Model Flags")
|
|
@@ -34,8 +43,14 @@ if st.button("Analyze"):
|
|
| 34 |
st.write(f"Using model: {model_id}")
|
| 35 |
|
| 36 |
# Perform sentiment analysis
|
| 37 |
-
|
| 38 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Closing the LD client
|
| 41 |
ld_client.close()
|
|
|
|
| 14 |
def get_model_config():
|
| 15 |
flag_key = "swap-sentiment-models" # Replace with your flag key
|
| 16 |
# Create context using Context builder
|
| 17 |
+
context = Context.builder("context-key-123abc").name("Erin").build()
|
| 18 |
flag_variation = ld_client.variation(flag_key, context, default={})
|
| 19 |
|
| 20 |
model_id = flag_variation.get("modelID", "distilbert-base-uncased")
|
| 21 |
return model_id
|
| 22 |
|
| 23 |
+
# Function to translate sentiment labels to user-friendly terms
|
| 24 |
+
def translate_label(label):
|
| 25 |
+
label_mapping = {
|
| 26 |
+
"LABEL_0": "🤬 Negative",
|
| 27 |
+
"LABEL_1": "😶 Neutral",
|
| 28 |
+
"LABEL_2": "😃 Positive"
|
| 29 |
+
}
|
| 30 |
+
return label_mapping.get(label, "Unknown")
|
| 31 |
+
|
| 32 |
|
| 33 |
# Streamlit app
|
| 34 |
st.title("Sentiment Analysis Demo with AI Model Flags")
|
|
|
|
| 43 |
st.write(f"Using model: {model_id}")
|
| 44 |
|
| 45 |
# Perform sentiment analysis
|
| 46 |
+
results = model(user_input)
|
| 47 |
+
st.write("Results:")
|
| 48 |
+
|
| 49 |
+
# Translate and display the results
|
| 50 |
+
for result in results:
|
| 51 |
+
label = translate_label(result['label'])
|
| 52 |
+
score = result['score']
|
| 53 |
+
st.write(f"Sentiment: {label}, Confidence: {score:.2f}")
|
| 54 |
|
| 55 |
# Closing the LD client
|
| 56 |
ld_client.close()
|