File size: 5,243 Bytes
5db9bfa
20267e3
a307e0c
20267e3
6b2c94c
20267e3
a307e0c
 
5016d60
a307e0c
eebd754
c08e12c
eebd754
 
7b5289a
81df7e3
 
 
a307e0c
81df7e3
a307e0c
81df7e3
 
 
a307e0c
5db9bfa
7b5289a
 
a307e0c
7b5289a
a307e0c
7b5289a
33f280f
 
09d98b3
a307e0c
 
 
 
33f280f
a307e0c
7b5289a
533dc39
aaa4f02
 
20267e3
5db9bfa
7b5289a
eebd754
222f176
7b5289a
20267e3
1ade275
20267e3
81df7e3
2b96966
eaf7247
 
20267e3
5db9bfa
3c724e6
baa99d7
3c724e6
20267e3
 
403361c
20267e3
a25a215
20267e3
fd995ba
abfe52c
781294f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a266b1
 
781294f
abfe52c
20267e3
 
fb07f7d
403361c
 
 
aa0a6b9
 
fb07f7d
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# import the relevant packages
import os
import csv
import openai
from openai import OpenAI
import gradio as gr
import huggingface_hub
from huggingface_hub import Repository
from datetime import datetime

client = OpenAI(
    api_key=os.environ.get("API_TOKEN"),
)

# recording requests to Hugging Face dataset
#DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
#DATA_FILENAME = "prompt_input.csv"
#DATA_FILE = os.path.join("data", DATA_FILENAME)

#HF_TOKEN = os.environ.get("HF_TOKEN")

#repo = Repository(
#    local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
#)

# function to store the message to the Hugging Face site, if you would like to add more columns or information to track add it here
def store_message(prompt: str, temperature: str, response: str):
    if prompt:
        with open(DATA_FILE, "a") as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=["prompt", "temperature", "response", "time"])
            writer.writerow(
                {"prompt": prompt, 
                 "temperature": temperature,
                 "response": response,
                 "time": str(datetime.now())}
            )
        commit_url = repo.push_to_hub()
        print(commit_url)

    return 

# defines who can enter the application with the secrets that are set up if used
user_db = { 
           os.environ["username"]: os.environ["password"],
          }

# the OpenAI function to use the given prompt to the model defined.
def mr_bot(prompt, tokens, temperature):
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=tokens,
        temperature=temperature,
        )
    # store_message(prompt=prompt, temperature=temperature, response=response.choices[0].message.content)
    
    return response.choices[0].message.content


# Gradio App interface and login set up
description = "Use the examples below to see how different prompts generate different results. Use the examples to see how different prompting " \
              "techniques can enhance your prompts. They are split into three sections, (creative writing, problem solving in business, and " \
              "philosophical debate) with three different levels of prompt engineering, (basic, intermediate, and advanced)."

demo = gr.Interface(fn=mr_bot, 
                    inputs=[gr.Textbox(placeholder="Select an example", interactive=False), gr.Slider(1, 800, value=800), gr.Slider(0.1, 1, value=0.75)], 
                    outputs="text",
                    title="Intro to AI, Prompt Engineering",
                    description=description,
                    cache_examples=False,
                    examples = [
                                            # Creative Writing
                        # Basic Prompt:
                        ["Write a story about a city.", 800, .90],
                        # Intermediate Prompt:
                        ["Write a story set in a futuristic city where technology controls everything.", 800, .90],
                        # Advanced Prompt:
                        ["Write a gripping tale set in a futuristic city named Neo-Philly, where an underground movement " \
                         "is fighting against the oppressive control of AI over human life, focusing on a protagonist who was once a loyal AI prompt engineer.", 800, .90],

                                            # Problem Solving in Business
                        # Basic Prompt:
                        ["A company needs to improve its profits.", 800, .90],
                        # Intermediate Prompt:
                        ["A retail company is seeing a decline in profits due to online competition. What can they do?", 800, .90],
                        # Advanced Prompt:
                        ["Devise a comprehensive strategy for a brick-and-mortar retail company that has been losing market share to e-commerce giants. " \
                         "Focus on innovative in-store experiences, digital integration, and customer loyalty programs to regain competitiveness.", 800, .90],

                                            # Philosophical Debate
                        # Basic Prompt:
                        ["Discuss the concept of happiness.", 800, .90],
                        # Intermediate Prompt:
                        ["Debate whether true happiness can be achieved through material wealth or if it's found in intangible experiences.", 800, .90],
                        # Advanced Prompt:
                        ["Critically analyze the philosophical arguments for and against the notion that true happiness is derived more from personal " \
                         "fulfillment and self-actualization than from material possessions, considering perspectives from both Eastern and " \
                         "Western philosophies.", 800, .90],
                    ]
                    )

if __name__ == "__main__":
    demo.launch(
        # enable_queue=False,
        ## if authentication is needed, uncomment below
        # auth=lambda u, p: user_db.get(u) == p,
        # auth_message="Welcome!"
               )