PeterBrendan commited on
Commit
ad51725
·
1 Parent(s): b2f8441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,25 +1,25 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- @st.cache_resource
5
- def load_model():
6
- return pipeline("text-generation", model="PeterBrendan/pbjs_gpt2")
7
 
8
  def main():
9
  if "generated_widget_id" not in st.session_state:
10
  st.session_state["generated_widget_id"] = None
11
 
12
  st.title("Prebid Config Generator")
13
- st.write("Enter a Prebid config setting, such as 'bidderTimeout', and get a generated Prebid config output starting from that setting onward. Using '{' will generate a Prebid config from the beginning.")
14
 
15
  st.subheader("Intended Uses")
16
- st.write("This model is designed to assist publishers in understanding and exploring how other publishers configure their Prebid settings. It can serve as a valuable reference to gain insights into common configurations, best practices, and different approaches used by publishers across various domains.")
17
- st.write("To learn more about the model, visit the [pbjs_gpt2 model page](https://huggingface.co/PeterBrendan/pbjs_gpt2). You can also refer to the [official Prebid Documentation on pbjs.setConfig](https://docs.prebid.org/dev-docs/publisher-api-reference/setConfig.html) for more information.")
18
 
19
- st.write("Note: The model may take some time to generate the output.")
20
 
21
  # Default prompts
22
- default_prompts = ["{", "bidderTimeout", "bidderSequence", "Usebidcache", "customPriceBucket"]
23
 
24
  # Create a selectbox for default prompts
25
  default_prompt = st.selectbox("Choose a default prompt:", default_prompts)
@@ -35,8 +35,11 @@ def main():
35
 
36
  # Check if the user input is empty
37
  if user_input:
 
 
 
38
  # Load the Hugging Face model
39
- generator = load_model()
40
 
41
  # Display 'Generating Output' message
42
  output_placeholder = st.empty()
@@ -44,7 +47,7 @@ def main():
44
  st.write("Generating Output...")
45
 
46
  # Generate text based on user input
47
- generated_text = generator(user_input, max_length=900, num_return_sequences=1)[0]["generated_text"]
48
 
49
  # Clear 'Generating Output' message and display the generated text
50
  output_placeholder.empty()
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ @st.cache(allow_output_mutation=True)
5
+ def load_model(model_name):
6
+ return pipeline("text-generation", model=model_name)
7
 
8
  def main():
9
  if "generated_widget_id" not in st.session_state:
10
  st.session_state["generated_widget_id"] = None
11
 
12
  st.title("Prebid Config Generator")
13
+ st.write("Enter a Prebid config setting, such as 'bidderTimeout', and get a generated Prebid config output starting from that setting onward. Using '{' will generate a Prebid config from the beginning. The model currently has a capped output of 760 characters.")
14
 
15
  st.subheader("Intended Uses")
16
+ st.write("This model is designed to assist publishers in understanding and exploring how most and advanced publishers configure their Prebid settings. It can serve as a valuable reference to gain insights into common configurations, best practices, and different approaches used by publishers across various domains. The model should be seen as a helpful tool to gain inspiration and understanding of common Prebid settings but not as a substitute for thorough testing and manual review of the final configurations.")
17
+ st.write("To learn more about the default model, visit the [pbjsGPT2 model page](https://huggingface.co/PeterBrendan/pbjs_gpt2). To learn more about the advanced model, visit the [pbjsGPT2v2 model page](https://huggingface.co/PeterBrendan/pbjsGPT2v2). You can also refer to the [official Prebid Documentation on pbjs.setConfig](https://docs.prebid.org/dev-docs/publisher-api-reference/setConfig.html) for more information.")
18
 
19
+ st.write("*Note:* The model may take some time to generate the output.")
20
 
21
  # Default prompts
22
+ default_prompts = ["{", "bidderTimeout", "bidderSequence", "Usebidcache", "customPriceBucket", "coppa"]
23
 
24
  # Create a selectbox for default prompts
25
  default_prompt = st.selectbox("Choose a default prompt:", default_prompts)
 
35
 
36
  # Check if the user input is empty
37
  if user_input:
38
+ # Select the model based on the user's choice
39
+ model_name = "PeterBrendan/pbjsGPT2v2" if st.button("Advanced Mode") else "PeterBrendan/pbjs_gpt2"
40
+
41
  # Load the Hugging Face model
42
+ generator = load_model(model_name)
43
 
44
  # Display 'Generating Output' message
45
  output_placeholder = st.empty()
 
47
  st.write("Generating Output...")
48
 
49
  # Generate text based on user input
50
+ generated_text = generator(user_input, max_length=760, num_return_sequences=1)[0]["generated_text"]
51
 
52
  # Clear 'Generating Output' message and display the generated text
53
  output_placeholder.empty()