LinyaJulya commited on
Commit
b4cc3e4
·
1 Parent(s): 500853c

Added Chatbot and other inputs

Browse files
Files changed (2) hide show
  1. app.py +45 -9
  2. 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 = "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"
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 Name\n- Description\n- Prompt Template\n- Instructions\n- Examples"
14
  },
15
  {
16
  "role": "user",
17
- "content": "Create a prompt template for: writing an automatic prompt with ChatGPT."
18
  },
19
  {
20
  "role": "assistant",
21
- "content": "Prompt Name: Automatic Prompt Template\n\nDescription: This allows people to create automatic prompts just from a few inputs.\n\nPrompt Template: You are an expert in [DOMAIN] and [SUB-DOMAIN] specializing in [SPECIFIC SKILL OR FOCUS]. You have helped many people before me to [PAST TASK RELATED TO THE DOMAIN]. Your task is now to [NEW TASK RELATED TO DOMAIN] from scratch. 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. Identify Your Domain: This is the broader category of your expertise (e.g., sales, financial audit, brand strategy).\n\n2. Specify the Sub-Domain: Narrow down your domain to a more specific area of expertise (e.g., customer relations, internal audit, brand launches).\n\n3. Determine the Specific Skill or Focus: Highlight a particular skill or task you excel at within the sub-domain (e.g., customer acquisition, auditing financial statements, launching successful brands).\n\n4. Recall a Past Task: Think of a task or achievement related to your domain that you have previously accomplished (e.g., developed strategies, audited financial statements, launched brands).\n\n5. Define the New Task: Describe what you want the AI to help with, related to your domain (e.g., develop strategies, audit a statement, create a brand strategy plan).\n\n6. Fill in the Template: Replace the placeholders in the template with the information from steps 1-5:\n ◦ Replace [DOMAIN] with your identified domain.\n ◦ Replace [SUB-DOMAIN] with your specified sub-domain.\n ◦ Replace [SPECIFIC SKILL OR FOCUS] with your determined skill or focus.\n ◦ Replace [PAST TASK RELATED TO THE DOMAIN] with your recalled past task.\n ◦ Replace [NEW TASK RELATED TO DOMAIN] with your defined new task.\n\n7. Input to ChatGPT: Once you've filled in the template, provide it to ChatGPT to receive expertise and insights based on the role and task you've described.\n\nExamples: \nExample 1:\n\"You are an expert in healthcare and pediatrics specializing in child nutrition. You have helped many people before me to advise on balanced diets for children. Your task is now to create a nutritious meal plan for a toddler from scratch. 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. Did you understand?\"\n\nExample 2:\n\"You are an expert in technology and software development specializing in mobile app creation. You have helped many people before me to develop innovative mobile applications. Your task is now to design a prototype for a fitness tracking app from scratch. 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. Did you understand?\"\n\nExample 3:\n\"You are an expert in agriculture and crop management specializing in organic farming. You have helped many people before me to establish organic farms. Your task is now to propose sustainable farming techniques for corn cultivation from scratch. 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. Did you understand?\""
 
 
 
 
 
 
 
 
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
- name = gr.Textbox(label="What do you need a prompt for?", placeholder="I need a prompt for...")
40
- output = gr.Textbox(label="Result")
41
- greet_btn = gr.Button("Generate")
42
- greet_btn.click(fn=chatbot_response, inputs=name, outputs=output, api_name="greet")
 
 
 
 
 
 
 
 
 
 
 
 
43
 
 
 
44
 
45
- demo.launch(share=True)
 
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