AilexGPT commited on
Commit
29df38b
1 Parent(s): 0694e7b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum", from_tf=True)
7
+
8
+ def generate(prompt, max_new_tokens):
9
+ batch = tokenizer(prompt, return_tensors="pt")
10
+ generated_ids = model.generate(batch["input_ids"], max_new_tokens=max_new_tokens)
11
+ output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
12
+ return output[0]
13
+
14
+ st.title("ChatGPT-BingChat Prompt Generator")
15
+ st.write("This app generates ChatGPT/BingChat & GPT-3 prompts using [this](https://huggingface.co/Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum) model trained by [Kaludi](https://huggingface.co/Kaludi/). Enter a role and a prompt will be generated based on it.")
16
+ prompt = st.text_input("Enter a Role, Example: Virtual Assistant", placeholder="Text here", value="")
17
+ max_new_tokens = st.slider("Select Max Tokens in Response", min_value=100, max_value=500, value=150, step=10)
18
+ if st.button("Generate"):
19
+ output = generate(prompt, max_new_tokens)
20
+ st.write("Generated Prompt:", box=True)
21
+ st.write("<div style='background-color: #2E2E2E; padding: 10px;'>{}</div>".format(output), unsafe_allow_html=True)
22
+ st.write("")
23
+ st.write("<div style='text-align: center; font-weight: bold;'>Examples:</div>",unsafe_allow_html=True, box=True)
24
+ st.write("<style> .stBox span { background-color: #2E2E2E; } </style>", unsafe_allow_html=True)
25
+ with open("examples.txt", "r") as f:
26
+ examples = f.readlines()
27
+ random_examples = random.sample(examples, 5)
28
+ for example in random_examples:
29
+ example = example.strip()
30
+ st.write("<div style='background-color: #2E2E2E; padding: 10px; text-align: center;'>• {}</div>".format(example), unsafe_allow_html=True)