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

Add concurrency

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from haystack.nodes import PromptNode
3
 
4
  from utils import lemmatizer_func
@@ -6,8 +7,13 @@ from utils import lemmatizer_func
6
  def run_prompt(prompt, api_key, model_name, max_length):
7
  prompt_node = PromptNode(model_name_or_path=model_name, api_key=api_key, max_length=max_length)
8
  lemmatized_prompt = lemmatizer_func(prompt)
9
- response_plain = prompt_node(prompt)
10
- response_lemmatized = prompt_node(lemmatized_prompt)
 
 
 
 
 
11
  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"]
12
 
13
  with gr.Blocks() as demo:
@@ -20,7 +26,7 @@ with gr.Blocks() as demo:
20
  gr.Examples(
21
  [
22
  ["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.\""],
23
- ["What's the Everett interpretation of quantum mechanics?"],
24
  ["Give me a list of the top 10 dive sites you would recommend around the world."],
25
  ["Can you tell me more about deep-water soloing?"],
26
  ["Can you write a short tweet about the Apache 2.0 release of our latest AI model, Falcon LLM?"],
 
1
  import gradio as gr
2
+ import concurrent.futures
3
  from haystack.nodes import PromptNode
4
 
5
  from utils import lemmatizer_func
 
7
  def run_prompt(prompt, api_key, model_name, max_length):
8
  prompt_node = PromptNode(model_name_or_path=model_name, api_key=api_key, max_length=max_length)
9
  lemmatized_prompt = lemmatizer_func(prompt)
10
+ with concurrent.futures.ThreadPoolExecutor() as executor:
11
+ future_plain = executor.submit(prompt_node, prompt)
12
+ future_lemmatized = executor.submit(prompt_node, lemmatized_prompt)
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:
 
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?"],