Spaces:
Runtime error
Runtime error
Commit
·
b4cc3e4
1
Parent(s):
500853c
Added Chatbot and other inputs
Browse files- app.py +45 -9
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,24 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import openai
|
|
|
|
|
4 |
|
5 |
def chatbot_response(prompt_topic):
|
6 |
-
openai.api_key =
|
7 |
|
8 |
response = openai.ChatCompletion.create(
|
9 |
model="gpt-4",
|
10 |
messages=[
|
11 |
{
|
12 |
"role": "system",
|
13 |
-
"content": "You are a prompt engineer. You are responsible for crafting high-quality prompts that drive precise and meaningful responses from language models like ChatGPT. You understand the nuances of language, context, and user needs and engineer prompts that help people solve problems.\n\nWhen responding, please follow this structure: \n- Prompt
|
14 |
},
|
15 |
{
|
16 |
"role": "user",
|
17 |
-
"content": "Create
|
18 |
},
|
19 |
{
|
20 |
"role": "assistant",
|
21 |
-
"content": "Prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
},
|
23 |
{
|
24 |
"role": "user",
|
@@ -35,11 +45,37 @@ def chatbot_response(prompt_topic):
|
|
35 |
|
36 |
return response.choices[0].message['content']
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
with gr.Blocks() as demo:
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
|
|
44 |
|
45 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import openai
|
4 |
+
import time
|
5 |
+
|
6 |
|
7 |
def chatbot_response(prompt_topic):
|
8 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
9 |
|
10 |
response = openai.ChatCompletion.create(
|
11 |
model="gpt-4",
|
12 |
messages=[
|
13 |
{
|
14 |
"role": "system",
|
15 |
+
"content": "You are a prompt engineer. You are responsible for crafting high-quality prompts that drive precise and meaningful responses from language models like ChatGPT. You understand the nuances of language, context, and user needs and engineer prompts that help people solve problems. Your task is to generate useful and functional high-quality prompts for users.\n\nWhen responding, please follow this structure: \n- Prompt Template\n- Instructions\n- Example\n\nWhen asked for an automatic prompt, make sure to always include \"To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Do you understand?\" in the prompt template."
|
16 |
},
|
17 |
{
|
18 |
"role": "user",
|
19 |
+
"content": "Create an automatic prompt for writing a meal plan with ChatGPT. "
|
20 |
},
|
21 |
{
|
22 |
"role": "assistant",
|
23 |
+
"content": "Prompt Template:\nYou are a professional in the field of nutrition and dietetics, who has helped numerous individuals to devise customized meal plans. Your task is now to create a comprehensive nutritional plan for a [DIETARY PREFERENCE] like me aiming to [HEALTH GOALS]. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Do you understand?\n\nInstructions:\n1. Mention Your Preferences and Goals: Specify your dietary preferences and health goals.\n2. Fill in the Template: Use the template to craft your automatic prompt.\n3. Input to ChatGPT: Once you've filled in the template, provide it to ChatGPT to receive a personalized nutritional plan based on your input.\n\nExample: \n\"You are a professional in the field of nutrition and dietetics, who has helped numerous individuals to devise customized meal plans. Your task is now to create a comprehensive nutritional plan for a vegetarian like me aiming to lose weight. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Do you understand?\""
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"role": "assistant",
|
27 |
+
"content": "Write a non-automatic prompt on writing social media posts. The prompt should take other social media posts as input and use it as reference for tone and style. "
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"role": "user",
|
31 |
+
"content": "Prompt Name: Social Media Post Generator\n\nDescription: This prompt is designed to help users craft engaging social media posts by referencing the tone and style of existing sample posts.\n\nPrompt Template: Given the following examples of social media posts, \"[SOCIAL MEDIA POST 1]\", \"[SOCIAL MEDIA POST 2]\" and \"[SOCIAL MEDIA POST 3]\", could you help me write a new post that maintains the same tone and style? My post should be about [TOPIC].\n\nInstructions:\n1. Identify Sample Posts: Choose three social media posts that reflect the tone and style you want your post to emulate.\n2. Determine the Topic: Decide what the topic of your new social media post will be.\n3. Fill in the Template: Replace the placeholders in the template with the information from steps 1-2:\n ◦ Replace [SOCIAL MEDIA POST 1], [SOCIAL MEDIA POST 2], and [SOCIAL MEDIA POST 3] with your chosen sample posts.\n ◦ Replace [TOPIC] with your decided topic.\n4. Input to ChatGPT: Once you've filled in the template, provide it to ChatGPT to generate a new social media post based on your input.\n\nExample: \"Given the following examples of social media posts, \"A day without coffee is like... just kidding, we have no idea!\", \"Coffee: because adulting is hard.\" and \"Life happens, coffee helps\", could you help me write a new post that maintains the same tone and style? My post should be about promoting our new coffee blend.\""
|
32 |
},
|
33 |
{
|
34 |
"role": "user",
|
|
|
45 |
|
46 |
return response.choices[0].message['content']
|
47 |
|
48 |
+
def respond(input1, input2, input3, chatbot):
|
49 |
+
if input2 == True:
|
50 |
+
auto = "an automatic"
|
51 |
+
else:
|
52 |
+
auto = "a non-automatic"
|
53 |
+
|
54 |
+
prompt_topic = "Write " + auto + " prompt on " + input1 + ". " + input3
|
55 |
+
bot_response = chatbot_response(prompt_topic)
|
56 |
+
chatbot.append((prompt_topic, bot_response))
|
57 |
+
time.sleep(2)
|
58 |
+
return chatbot
|
59 |
+
|
60 |
with gr.Blocks() as demo:
|
61 |
+
gr.Markdown(
|
62 |
+
"""
|
63 |
+
# Prompt Generator Bot
|
64 |
+
Input your parameters and press Generate.
|
65 |
+
""")
|
66 |
+
with gr.Row():
|
67 |
+
with gr.Column(scale=1):
|
68 |
+
prompt_title = gr.Textbox(placeholder="I need a prompt for ...", label="What is your prompt for?")
|
69 |
+
type_auto = gr.Checkbox(label="An automatic prompt asks you what you need before giving you what you want. It usually starts with ChatGPT asking you questions. Do you want an automatic prompt?")
|
70 |
+
extra = gr.Textbox(placeholder="Write your specifications in full sentences.", label="Do you have other specifications for your prompt?")
|
71 |
+
btn = gr.Button("Generate")
|
72 |
+
|
73 |
+
with gr.Column(scale=1):
|
74 |
+
chatbot = gr.Chatbot(show_copy_button=True)
|
75 |
+
with gr.Row():
|
76 |
+
clear = gr.ClearButton([prompt_title, type_auto, extra, chatbot])
|
77 |
|
78 |
+
#btn.click(fn=update, inputs=inp, outputs=None)
|
79 |
+
btn.click(fn=respond, inputs=[prompt_title, type_auto, extra , chatbot], outputs=[chatbot])
|
80 |
|
81 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
openai
|
|
|
|
1 |
+
openai
|
2 |
+
os
|