piusanalytics commited on
Commit
85a0cec
·
verified ·
1 Parent(s): dc397f2

create gradio app

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import keras
2
+ import keras_nlp
3
+ import gradio as gr
4
+ import os
5
+ import re
6
+
7
+ # Get Secrets
8
+ os.environ["KAGGLE_USERNAME"] = os.getenv('KAGGLE_USERNAME')
9
+ os.environ["KAGGLE_KEY"] = os.getenv('KAGGLE_KEY')
10
+ os.environ["KERAS_BACKEND"] = "jax"
11
+
12
+ # Establish LLM
13
+ gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset("gemma_instruct_2b_en")
14
+ sampler = keras_nlp.samplers.TopKSampler(k=1, seed=42)
15
+ gemma_lm.compile(sampler=sampler)
16
+
17
+ # Template
18
+ template = """Your task is to enhance user provided prompts for large language models.
19
+ Use the following guidelines between backticks to improve prompts.
20
+ ```
21
+ Be specific: Clearly state your desired outcome or the type of information you're seeking. The more specific and focused your prompt is, the better chances you have of obtaining accurate and useful responses.
22
+ Provide context: Offer relevant background information to set the stage and ensure that the model understands the context of your request. This to generate more informed and context-aware responses.
23
+ Use explicit instructions: If you want the model to perform a specific task, make your instructions explicit. Specify the format, structure, or steps required for the response. For example, instead of asking for a "description," you could write a "step-by-step description" or a "brief summary."
24
+ Ask for pros and cons: If you're seeking an evaluation or comparison, explicitly ask for the advantages and disadvantages of a particular topic or approach.
25
+ ```
26
+ Return an enhanced version of the following prompt provided by the Human.
27
+ Human:{query}
28
+ """
29
+
30
+ # Build Gradio App
31
+ def process_input(input_text):
32
+ # Process the input here and generate the output
33
+ prompt = template.format(
34
+ query =input_text
35
+ )
36
+ gemma_output = gemma_lm.generate(prompt, max_length=1024)
37
+ output = re.search(r'Enhanced prompt: (.+)', gemma_output).group(1).strip()
38
+ return output
39
+
40
+ # Create the input interface
41
+ input_textbox = gr.Textbox(label="Enter your Prompt")
42
+
43
+ # Create the output interface
44
+ output_textbox = gr.Textbox(label="Enhanced Prompt")
45
+
46
+ # Create the Gradio app
47
+ gr.Interface(
48
+ fn=process_input,
49
+ inputs=input_textbox,
50
+ outputs=output_textbox,
51
+ title="Auto Prompt Engineer",
52
+ description="Enter your prompt and get it evaluated and enchanced for Free!",
53
+ theme="huggingface"
54
+ ).launch()