bilgeyucel commited on
Commit
3b27821
1 Parent(s): 7ffbb99

Improve the application UI

Browse files
Files changed (2) hide show
  1. README.md +23 -1
  2. app.py +29 -18
README.md CHANGED
@@ -9,4 +9,26 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # Prompt Lemmatizer
13
+
14
+ ### Try it out on [🤗 Spaces](https://huggingface.co/spaces/bilgeyucel/prompt-lemmatizer)
15
+
16
+ ##### A simple app to compare the effect of lemmatization on prompts
17
+
18
+ This is a demo just for fun 🥳 Feel free to open a PR for improvements!
19
+
20
+ It's been built with [Haystack](https://haystack.deepset.ai) using the [`PromptNode`](https://docs.haystack.deepset.ai/docs/prompt_node).
21
+
22
+ ## To learn more about the PromptNode
23
+
24
+ Check out our tutorial on the PromptNode and how to create your own templates [here](https://haystack.deepset.ai/tutorials/21_customizing_promptnode)
25
+
26
+ ## Installation and Running
27
+ 1. Install requirements:
28
+ `pip install -r requirements.txt`
29
+ 2. Run the gradio app:
30
+ `python app.py`
31
+
32
+ This will start up the app on `http://127.0.0.1:7860`.
33
+
34
+ #### The Haystack Community is on [Discord](https://discord.gg/haystack)
app.py CHANGED
@@ -13,40 +13,51 @@ def run_prompt(prompt, api_key, model_name, max_length):
13
 
14
  response_plain = future_plain.result()
15
  response_lemmatized = future_lemmatized.result()
16
-
17
  return lemmatized_prompt, response_plain[0][0], response_plain[1]["prompt_tokens"], response_plain[1]["completion_tokens"], response_lemmatized[0][0], response_lemmatized[1]["prompt_tokens"], response_lemmatized[1]["completion_tokens"]
18
 
 
 
 
 
 
 
 
 
 
19
  with gr.Blocks() as demo:
 
20
  with gr.Row():
21
- api_key = gr.Textbox(label="Enter your api key")
22
  model_name = gr.Dropdown(["text-davinci-003", "gpt-3.5-turbo", "gpt-4", "gpt-4-32k", "command", "command-light", "base", "base-light"], value="gpt-3.5-turbo", label="Choose your model!")
23
  max_length = gr.Slider(100, 500, value=100, step=10, label="Max Length", info="Max token length of the response. Choose between 100 and 500")
24
  with gr.Row():
25
  prompt = gr.TextArea(label="Prompt", value="Rachel has 17 apples. She gives 9 to Sarah. How many apples does Rachel have now?")
26
  gr.Examples(
27
  [
28
- ["I want you to act as a travel guide. I will write you my location and you will suggest a place to visit near my location. In some cases, I will also give you the type of places I will visit. You will also suggest me places of similar type that are close to my first location. My first suggestion request is \"I am in Italy and I want to visit only museums.\""],
29
- ["Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance. Explain the above in one sentence:"],
30
- ["Give me a list of the top 10 dive sites you would recommend around the world."],
31
- ["Can you tell me more about deep-water soloing?"],
32
- ["Can you write a short tweet about the Apache 2.0 release of our latest AI model, Falcon LLM?"],
33
  ],
34
  inputs=prompt,
35
- label="Click on any example and press Enter in the input textbox!",
36
- )
37
  submit_btn = gr.Button("Submit")
38
  with gr.Row():
39
- prompt_response = gr.TextArea(label="Answer", show_copy_button=True)
40
  with gr.Column():
41
- token_count_plain = gr.Number(label="Prompt Token Count")
42
- token_count_plain_completion = gr.Number(label="Completion Token Count")
43
- with gr.Row():
44
- lemmatized_prompt_response = gr.TextArea(label="Lemmatized Answer", show_copy_button=True)
45
  with gr.Column():
46
- lemmatized_prompt = gr.TextArea(label="Lemmatized Promp", show_copy_button=True)
47
- token_count_lemmatized = gr.Number(label="Lemmatized Text Token Count")
48
- token_count_lemmatized_completion = gr.Number(label="Completion Lemmatized Token Count")
 
 
 
 
49
  submit_btn.click(fn=run_prompt, inputs=[prompt, api_key, model_name, max_length], outputs=[lemmatized_prompt, prompt_response, token_count_plain, token_count_plain_completion, lemmatized_prompt_response, token_count_lemmatized, token_count_lemmatized_completion])
50
 
51
- demo.launch()
 
52
 
 
13
 
14
  response_plain = future_plain.result()
15
  response_lemmatized = future_lemmatized.result()
 
16
  return lemmatized_prompt, response_plain[0][0], response_plain[1]["prompt_tokens"], response_plain[1]["completion_tokens"], response_lemmatized[0][0], response_lemmatized[1]["prompt_tokens"], response_lemmatized[1]["completion_tokens"]
17
 
18
+ description = """
19
+ # Prompt Lemmatizer 🐢
20
+ ## Lemmatize your prompts and compare the outputs of lemmatized and non-lemmatized versions.
21
+
22
+ Enter an OpenAI or Cohere key, choose your model and set the `max_length`.
23
+
24
+ Built by [Bilge Yucel](https://twitter.com/bilgeycl) and [Stefano Fiorucci](https://github.com/anakin87), with [Haystack](https://github.com/deepset-ai/haystack).
25
+ """
26
+
27
  with gr.Blocks() as demo:
28
+ gr.Markdown(value=description)
29
  with gr.Row():
30
+ api_key = gr.Textbox(label="Enter your api key", type="password")
31
  model_name = gr.Dropdown(["text-davinci-003", "gpt-3.5-turbo", "gpt-4", "gpt-4-32k", "command", "command-light", "base", "base-light"], value="gpt-3.5-turbo", label="Choose your model!")
32
  max_length = gr.Slider(100, 500, value=100, step=10, label="Max Length", info="Max token length of the response. Choose between 100 and 500")
33
  with gr.Row():
34
  prompt = gr.TextArea(label="Prompt", value="Rachel has 17 apples. She gives 9 to Sarah. How many apples does Rachel have now?")
35
  gr.Examples(
36
  [
37
+ "I want you to act as a travel guide. I will write you my location and you will suggest a place to visit near my location. In some cases, I will also give you the type of places I will visit. You will also suggest me places of similar type that are close to my first location. My first suggestion request is \"I am in Italy and I want to visit only museums.\"",
38
+ "Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance. Explain the above in one sentence:",
39
+ "Please give a sentiment for this context. Answer with positive, negative or neutral. Context: A flicker in the dark started of interesting and I was glued to the novel. It was just a little longer that I had anticipated to get to the bottom of the story. I felt sorry for the Chloe's mother but I had thought there was something odd about her brother. Well being a murderer was it any wonder he did not like this sister's boyfriend because I think he knew what happened. I love the cover of the book and the title is good. If only hardbacks had the cover printed onto them. Answer:",
 
 
40
  ],
41
  inputs=prompt,
42
+ label="Click on any example and press Submit!"
43
+ )
44
  submit_btn = gr.Button("Submit")
45
  with gr.Row():
 
46
  with gr.Column():
47
+ prompt_response = gr.TextArea(label="Output", show_copy_button=True)
48
+ with gr.Row():
49
+ token_count_plain = gr.Number(label="Prompt Token Count")
50
+ token_count_plain_completion = gr.Number(label="Output Token Count")
51
  with gr.Column():
52
+ lemmatized_prompt_response = gr.TextArea(label="Output (Lemmatized Prompt)", show_copy_button=True)
53
+ with gr.Row():
54
+ token_count_lemmatized = gr.Number(label="Lemmatized Prompt Token Count")
55
+ token_count_lemmatized_completion = gr.Number(label="Output Token Count (Lemmatized Prompt)")
56
+ with gr.Accordion("See Lemmatized Prompt", open=False):
57
+ lemmatized_prompt = gr.TextArea(show_copy_button=True, show_label=False, container=False)
58
+
59
  submit_btn.click(fn=run_prompt, inputs=[prompt, api_key, model_name, max_length], outputs=[lemmatized_prompt, prompt_response, token_count_plain, token_count_plain_completion, lemmatized_prompt_response, token_count_lemmatized, token_count_lemmatized_completion])
60
 
61
+ if __name__ == "__main__":
62
+ demo.launch()
63