Spaces:
Sleeping
Sleeping
File size: 1,713 Bytes
6d5f1d4 59bb781 f749ddc ca036aa 6d5f1d4 f749ddc 6d5f1d4 78c899f ca036aa 78c899f 6d5f1d4 ca036aa a1978ee 78c899f 6d5f1d4 f749ddc ca036aa 6d5f1d4 ca036aa 6d5f1d4 ca036aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import openai
import os
import gradio as gr
openai.api_key = os.environ['openai']
def write_essay(prompt, character, temperature, frequency_penalty, presence_penalty):
model="gpt-3.5-turbo"
temp_list = prompt.split()
temp_list2 = character.split()
temperature = temperature/10
frequency_penalty = frequency_penalty/10 - 2
presence_penalty = presence_penalty/10 -2
new_prompt = " ".join(temp_list[0:150])
new_prompt2 = " ".join(temp_list2[0:50])
response = openai.ChatCompletion.create(
model=model,
messages=[{"role": "system", "content": new_prompt2},
{"role": "user", "content": new_prompt},],
stream=False,
max_tokens=250,
temperature=temperature,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty
)
message = response.choices[0]["message"]["content"]
#print(message)
return message
demo = gr.Interface(fn=write_essay, inputs=[gr.Textbox(label="Prompt",info="Your Request",lines=5, value=""),gr.Textbox(label="Characteristic of the AI",info="Put Character for AI",lines=1, value=""),
gr.Slider(0, 20, value=4, step=1, label="Creative vs Focus", info="Increase for creative and decrease for more focused"),
gr.Slider(0, 40, value=20, step=1, label="Frequency of words", info="Increase to decrease repeated words"),
gr.Slider(0, 40, value=20, step=1, label="Presence of words", info="Increase to decrease already appeared words")
], outputs="text")
demo.launch() |