Polarisailabs's picture
Update app.py
27db63f verified
from openai import OpenAI
import gradio as gr
messages = [
{"role": "system", "content": "You are AI specialized in Prompt Engineering"},
]
client = OpenAI(api_key="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", base_url="https://openrouter.ai/api/v1")
def chatbot(input, prompt_type):
if input:
if prompt_type == "Zero Shot Prompt":
input += ""
elif prompt_type == "One Shot Prompt":
input += " Convert this zero shot prompt to one shot prompt"
elif prompt_type == "Few Shot Prompt":
input += " Convert this zero shot prompt to few shot prompt"
elif prompt_type == "System Prompt":
input += " Convert this zero shot prompt to system prompt"
elif prompt_type == "Contextual Prompt":
input += " Convert this zero shot prompt to contextual prompt"
elif prompt_type == "Role Prompt":
input += " Convert this zero shot prompt to role prompt"
elif prompt_type == "Step-back Prompt":
input += " Convert this zero shot prompt to step-back prompt"
elif prompt_type == "Chain-of-thought Prompt":
input += " Convert this zero shot prompt to chain-of-thought prompt"
elif prompt_type == "Tree-of-thought":
input += " Convert this zero shot prompt to tree-of-thought prompt"
elif prompt_type == "React Prompt":
input += " Convert this zero shot prompt to react prompt"
elif prompt_type == "Code Prompt":
input += " Convert this zero shot prompt to code prompt"
elif prompt_type == "Multi-Modal Prompt":
input += " Convert this zero shot prompt to multi-Modal prompt"
elif prompt_type == "Augmented Prompt":
input += " Convert this zero shot prompt to augmented prompt"
messages.append({"role": "user", "content": f"{prompt_type}: {input}"})
chat = client.chat.completions.create(
model="deepseek/deepseek-r1:free", messages=messages
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
prompt_types = [
"Zero Shot Prompt",
"One Shot Prompt",
"Few Shot Prompt",
"System Prompt",
"Contextual Prompt",
"Role Prompt",
"Step-back Prompt",
"Chain-of-thought Prompt",
"Tree-of-thought Prompt",
"React Prompt",
"Code Prompt",
"Multi-Modal Prompt",
"Augmented Prompt"
]
with gr.Blocks() as demo:
dropdown = gr.Dropdown(choices=prompt_types, label="Select Prompt Type", type="value")
inputs = gr.Textbox(lines=7, label="Prompt : Try - What is the value of pi")
outputs = gr.Textbox(label="Result")
gr.Interface(fn=chatbot, inputs=[inputs, dropdown], outputs=outputs, theme="compact")
demo.launch(share=True)