erinmikail commited on
Commit
dc64cbc
·
verified ·
1 Parent(s): da3cfe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -2
app.py CHANGED
@@ -1,4 +1,37 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+ import launchdarkly_api
4
 
5
+ # Initialize LaunchDarkly client
6
+ ld_client = launchdarkly_api.LDClient("YOUR_LAUNCHDARKLY_SDK_KEY")
7
+
8
+ # Model descriptions
9
+ model_descriptions = {
10
+ "bert-base-uncased": "BERT base model (uncased)",
11
+ "roberta-base": "RoBERTa base model",
12
+ "distilbert-base-uncased": "DistilBERT base model (uncased)",
13
+ "albert-base-v2": "ALBERT base model v2"
14
+ }
15
+
16
+ # Create a function to get the active model from LaunchDarkly
17
+ def get_active_model():
18
+ if ld_client.variation("use_bert", {"key": "user"}):
19
+ return pipeline("sentiment-analysis", model="bert-base-uncased"), "bert-base-uncased"
20
+ elif ld_client.variation("use_roberta", {"key": "user"}):
21
+ return pipeline("sentiment-analysis", model="roberta-base"), "roberta-base"
22
+ elif ld_client.variation("use_distilbert", {"key": "user"}):
23
+ return pipeline("sentiment-analysis", model="distilbert-base-uncased"), "distilbert-base-uncased"
24
+ elif ld_client.variation("use_albert", {"key": "user"}):
25
+ return pipeline("sentiment-analysis", model="albert-base-v2"), "albert-base-v2"
26
+ else:
27
+ return pipeline("sentiment-analysis", model="distilbert-base-uncased"), "distilbert-base-uncased" # Default model
28
+
29
+ # Streamlit app
30
+ st.title("Sentiment Analysis Demo")
31
+ user_input = st.text_area("Enter text for sentiment analysis:")
32
+
33
+ if st.button("Analyze"):
34
+ model, model_name = get_active_model()
35
+ result = model(user_input)
36
+ st.write(f"Model used: {model_descriptions[model_name]}")
37
+ st.write(result)