Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,76 +1,41 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
import gradio as gr
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
elif prompt_type == "System Prompt":
|
| 28 |
-
input += " Convert this zero shot prompt to system prompt"
|
| 29 |
-
elif prompt_type == "Contextual Prompt":
|
| 30 |
-
input += " Convert this zero shot prompt to contextual prompt"
|
| 31 |
-
elif prompt_type == "Role Prompt":
|
| 32 |
-
input += " Convert this zero shot prompt to role prompt"
|
| 33 |
-
elif prompt_type == "Step-back Prompt":
|
| 34 |
-
input += " Convert this zero shot prompt to step-back prompt"
|
| 35 |
-
elif prompt_type == "Chain-of-thought Prompt":
|
| 36 |
-
input += " Convert this zero shot prompt to chain-of-thought prompt"
|
| 37 |
-
elif prompt_type == "Tree-of-thought":
|
| 38 |
-
input += " Convert this zero shot prompt to tree-of-thought prompt"
|
| 39 |
-
elif prompt_type == "React Prompt":
|
| 40 |
-
input += " Convert this zero shot prompt to react prompt"
|
| 41 |
-
elif prompt_type == "Code Prompt":
|
| 42 |
-
input += " Convert this zero shot prompt to code prompt"
|
| 43 |
-
elif prompt_type == "Multi-Modal Prompt":
|
| 44 |
-
input += " Convert this zero shot prompt to multi-Modal prompt"
|
| 45 |
-
elif prompt_type == "Augmented Prompt":
|
| 46 |
-
input += " Convert this zero shot prompt to augmented prompt"
|
| 47 |
-
|
| 48 |
-
messages.append({"role": "user", "content": f"{prompt_type}: {input}"})
|
| 49 |
-
chat = client.chat.completions.create(
|
| 50 |
-
model="deepseek/deepseek-r1:free", messages=messages
|
| 51 |
-
)
|
| 52 |
-
reply = chat.choices[0].message.content
|
| 53 |
-
messages.append({"role": "assistant", "content": reply})
|
| 54 |
-
return reply
|
| 55 |
-
|
| 56 |
-
prompt_types = [
|
| 57 |
-
"Zero Shot Prompt",
|
| 58 |
-
"One Shot Prompt",
|
| 59 |
-
"Few Shot Prompt",
|
| 60 |
-
"System Prompt",
|
| 61 |
-
"Contextual Prompt",
|
| 62 |
-
"Role Prompt",
|
| 63 |
-
"Step-back Prompt",
|
| 64 |
-
"Chain-of-thought Prompt",
|
| 65 |
-
"Tree-of-thought Prompt",
|
| 66 |
-
"React Prompt",
|
| 67 |
-
"Code Prompt",
|
| 68 |
-
"Multi-Modal Prompt",
|
| 69 |
-
"Augmented Prompt"
|
| 70 |
-
]
|
| 71 |
-
with gr.Blocks(theme=gr.themes.Default(primary_hue="sky")) as promptengineering:
|
| 72 |
-
dropdown = gr.Dropdown(choices=prompt_types, label="Select Prompt Type:", type="value")
|
| 73 |
-
inputs = gr.Textbox(lines=7, label ="",placeholder="Prompt : Try - What is the value of pi")
|
| 74 |
-
outputs = gr.Textbox(label="Response:")
|
| 75 |
-
gr.Interface(fn=chatbot, inputs=[dropdown,inputs], outputs=outputs)
|
| 76 |
promptengineering.launch(share=True)
|
|
|
|
| 1 |
+
_O='Augmented Prompt'
|
| 2 |
+
_N='Multi-Modal Prompt'
|
| 3 |
+
_M='Code Prompt'
|
| 4 |
+
_L='React Prompt'
|
| 5 |
+
_K='Chain-of-thought Prompt'
|
| 6 |
+
_J='Step-back Prompt'
|
| 7 |
+
_I='Role Prompt'
|
| 8 |
+
_H='Contextual Prompt'
|
| 9 |
+
_G='System Prompt'
|
| 10 |
+
_F='Few Shot Prompt'
|
| 11 |
+
_E='One Shot Prompt'
|
| 12 |
+
_D='Zero Shot Prompt'
|
| 13 |
+
_C='API_KEY'
|
| 14 |
+
_B='content'
|
| 15 |
+
_A='role'
|
| 16 |
import os
|
| 17 |
from openai import OpenAI
|
| 18 |
import gradio as gr
|
| 19 |
+
API_KEY=os.environ[_C]
|
| 20 |
+
messages=[{_A:'system',_B:'You are AI specialized in Prompt Engineering'}]
|
| 21 |
+
client=OpenAI(base_url='https://openrouter.ai/api/v1',api_key=_C,default_headers={'Authorization':f"Bearer {API_KEY}",'HTTP-Referer':'','X-Title':''})
|
| 22 |
+
def chatbot(input,prompt_type):
|
| 23 |
+
A=prompt_type
|
| 24 |
+
if input:
|
| 25 |
+
if A==_D:input+=''
|
| 26 |
+
elif A==_E:input+=' Convert this zero shot prompt to one shot prompt'
|
| 27 |
+
elif A==_F:input+=' Convert this zero shot prompt to few shot prompt'
|
| 28 |
+
elif A==_G:input+=' Convert this zero shot prompt to system prompt'
|
| 29 |
+
elif A==_H:input+=' Convert this zero shot prompt to contextual prompt'
|
| 30 |
+
elif A==_I:input+=' Convert this zero shot prompt to role prompt'
|
| 31 |
+
elif A==_J:input+=' Convert this zero shot prompt to step-back prompt'
|
| 32 |
+
elif A==_K:input+=' Convert this zero shot prompt to chain-of-thought prompt'
|
| 33 |
+
elif A=='Tree-of-thought':input+=' Convert this zero shot prompt to tree-of-thought prompt'
|
| 34 |
+
elif A==_L:input+=' Convert this zero shot prompt to react prompt'
|
| 35 |
+
elif A==_M:input+=' Convert this zero shot prompt to code prompt'
|
| 36 |
+
elif A==_N:input+=' Convert this zero shot prompt to multi-Modal prompt'
|
| 37 |
+
elif A==_O:input+=' Convert this zero shot prompt to augmented prompt'
|
| 38 |
+
messages.append({_A:'user',_B:f"{A}: {input}"});C=client.chat.completions.create(model='deepseek/deepseek-r1:free',messages=messages);B=C.choices[0].message.content;messages.append({_A:'assistant',_B:B});return B
|
| 39 |
+
prompt_types=[_D,_E,_F,_G,_H,_I,_J,_K,'Tree-of-thought Prompt',_L,_M,_N,_O]
|
| 40 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue='sky'))as promptengineering:dropdown=gr.Dropdown(choices=prompt_types,label='Select Prompt Type:',type='value');inputs=gr.Textbox(lines=7,label='',placeholder='Prompt : Try - What is the value of pi');outputs=gr.Textbox(label='Response:');gr.Interface(fn=chatbot,inputs=[dropdown,inputs],outputs=outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
promptengineering.launch(share=True)
|