Spaces:
Sleeping
Sleeping
PeterBrendan
commited on
Commit
•
46c3cfd
1
Parent(s):
e194459
Upload 2 files
Browse files- app.py +50 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model(model_name):
|
7 |
+
return pipeline("text-generation", model=model_name)
|
8 |
+
|
9 |
+
def main():
|
10 |
+
st.title("Prebid Module Generator")
|
11 |
+
st.write("Enter a Prebid module, such as 'appnexusBidAdapter', and get a generated Prebid installed module output starting from that setting onward. Using '[' will generate a Prebid config from the beginning. The model currently has a capped output of 1000 characters.")
|
12 |
+
|
13 |
+
st.subheader("Intended Uses")
|
14 |
+
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 modules but not as a substitute for thorough testing and manual review of the final modules useds.")
|
15 |
+
st.write("To learn more about the default model, visit the [Prebid_Module_GPT2 model page](https://huggingface.co/PeterBrendan/Prebid_Module_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.")
|
16 |
+
|
17 |
+
st.write("*Note:* The model may take some time to generate the output.")
|
18 |
+
|
19 |
+
# Create a text input field for user prompt
|
20 |
+
user_input = st.text_input("Enter a Prebid module:", "")
|
21 |
+
|
22 |
+
# Check if the user input is empty
|
23 |
+
if user_input:
|
24 |
+
# Select the model
|
25 |
+
model_name = "PeterBrendan/Prebid_Module_GPT2"
|
26 |
+
|
27 |
+
# Load the Hugging Face model
|
28 |
+
generator = load_model(model_name)
|
29 |
+
|
30 |
+
# Display 'Generating Output' message
|
31 |
+
output_placeholder = st.empty()
|
32 |
+
with output_placeholder:
|
33 |
+
st.write("Generating Output...")
|
34 |
+
|
35 |
+
# Generate text based on user input
|
36 |
+
generated_text = generator(user_input, max_length=1000, num_return_sequences=1)[0]["generated_text"]
|
37 |
+
|
38 |
+
# Clear 'Generating Output' message and display the generated text
|
39 |
+
output_placeholder.empty()
|
40 |
+
st.write("Generated Text:")
|
41 |
+
try:
|
42 |
+
parsed_json = json.loads(generated_text)
|
43 |
+
beautified_json = json.dumps(parsed_json, indent=4)
|
44 |
+
st.code(beautified_json, language="json")
|
45 |
+
except json.JSONDecodeError:
|
46 |
+
st.write(generated_text)
|
47 |
+
|
48 |
+
# Run the app
|
49 |
+
if __name__ == "__main__":
|
50 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==0.84.1
|
2 |
+
transformers>=4.11.3
|
3 |
+
torch>=1.9.0
|