erinmikail commited on
Commit
8d352e6
β€’
1 Parent(s): 7aee41a

make the labels visible instead of just a number oh and add a cute emoji!

Browse files
Files changed (1) hide show
  1. app.py +18 -3
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("Sandy").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
 
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
- result = model(user_input)
38
- st.write(result)
 
 
 
 
 
 
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()