isayahc commited on
Commit
cd31e3b
1 Parent(s): 3795f1b

made app.py more readable

Browse files
Files changed (1) hide show
  1. app.py +7 -38
app.py CHANGED
@@ -4,27 +4,12 @@ from structured_apparatus_chain import (
4
  pub_med_chain as apparatus_pub_med_chain,
5
  wikipedia_chain as apparatus_wikipedia_chain
6
  )
7
-
8
  from structured_experiment_chain import (
9
  arxiv_chain as experiment_arxiv_chain,
10
  pub_med_chain as experiment_pub_med_chain,
11
  wikipedia_chain as experiment_wikipedia_chain
12
  )
13
 
14
-
15
-
16
- # apparatus_examples = [
17
- # "Microscope",
18
- # "I don't fucking know yet",
19
- # ]
20
-
21
- # apparatus_examples = {
22
- # ["sample": "cool"],
23
- # ["guitar": "john"],
24
- # }
25
-
26
- # apparatus_examples = [apparatus_examples]
27
-
28
  apparatus_retriever_options = {
29
  "Arxiv": apparatus_arxiv_chain,
30
  "PubMed": apparatus_pub_med_chain,
@@ -37,52 +22,36 @@ experiment_retriever_options = {
37
  "Wikipedia": experiment_wikipedia_chain,
38
  }
39
 
40
- # experiment_retriever_options = ["Option 1", "Option 2", "Option 3"]
41
-
42
  def generate_apparatus(input_text, retriever_choice):
43
- # Retrieve the appropriate chain based on the selected option
44
  selected_chain = apparatus_retriever_options[retriever_choice]
45
- # Execute the selected chain with the input text
46
  output_text = selected_chain.invoke(input_text)
47
  return output_text
48
 
49
  def generate_experiment(input_text, retriever_choice):
50
- # Retrieve the appropriate chain based on the selected option
51
- selected_chain = apparatus_retriever_options[retriever_choice]
52
- # Execute the selected chain with the input text
53
  output_text = selected_chain.invoke(input_text)
54
  return output_text
55
 
56
  generate_apparatus_interface = gr.Interface(
57
  fn=generate_apparatus,
58
- inputs=["text", gr.Radio(choices=list(apparatus_retriever_options.keys()), label="Select a retriever")],
59
  outputs="text",
60
  title="Generate Apparatus",
61
  description="I am here to help makers make more and learn the science behind things",
62
- # examples=apparatus_examples,
63
  )
64
 
65
- experiment_apparatus_interface = gr.Interface(
66
  fn=generate_experiment,
67
- inputs=["text", gr.Radio(choices=list(experiment_retriever_options.keys()), label="Select a retriever")],
68
  outputs="text",
69
  title="Generate an experiment",
70
- description="I am here to generate a store science experiments for our users",
71
- # examples=apparatus_examples,
72
  )
73
 
74
- # stt_demo = gr.Interface(
75
- # fn="huggingface/facebook/wav2vec2-base-960h",
76
- # inputs=gr.Microphone(type="filepath"),
77
- # outputs=None,
78
- # title="Generate Experiment",
79
- # description="Let me try to guess what you're saying!"
80
- # )
81
-
82
  demo = gr.TabbedInterface([
83
  generate_apparatus_interface,
84
- experiment_apparatus_interface,
85
- ], ["Generate Apparatus", "Generate Experiment"])
86
 
87
  if __name__ == "__main__":
88
  demo.launch()
 
4
  pub_med_chain as apparatus_pub_med_chain,
5
  wikipedia_chain as apparatus_wikipedia_chain
6
  )
 
7
  from structured_experiment_chain import (
8
  arxiv_chain as experiment_arxiv_chain,
9
  pub_med_chain as experiment_pub_med_chain,
10
  wikipedia_chain as experiment_wikipedia_chain
11
  )
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  apparatus_retriever_options = {
14
  "Arxiv": apparatus_arxiv_chain,
15
  "PubMed": apparatus_pub_med_chain,
 
22
  "Wikipedia": experiment_wikipedia_chain,
23
  }
24
 
 
 
25
  def generate_apparatus(input_text, retriever_choice):
 
26
  selected_chain = apparatus_retriever_options[retriever_choice]
 
27
  output_text = selected_chain.invoke(input_text)
28
  return output_text
29
 
30
  def generate_experiment(input_text, retriever_choice):
31
+ selected_chain = experiment_retriever_options[retriever_choice]
 
 
32
  output_text = selected_chain.invoke(input_text)
33
  return output_text
34
 
35
  generate_apparatus_interface = gr.Interface(
36
  fn=generate_apparatus,
37
+ inputs=["text", gr.Radio(choices=list(apparatus_retriever_options.keys()), label="Select a retriever", value="Wikipedia")],
38
  outputs="text",
39
  title="Generate Apparatus",
40
  description="I am here to help makers make more and learn the science behind things",
 
41
  )
42
 
43
+ generate_experiment_interface = gr.Interface(
44
  fn=generate_experiment,
45
+ inputs=["text", gr.Radio(choices=list(experiment_retriever_options.keys()), label="Select a retriever", value="Wikipedia")],
46
  outputs="text",
47
  title="Generate an experiment",
48
+ description="I am here to generate and store science experiments for our users",
 
49
  )
50
 
 
 
 
 
 
 
 
 
51
  demo = gr.TabbedInterface([
52
  generate_apparatus_interface,
53
+ generate_experiment_interface,
54
+ ], ["Generate Apparatus", "Generate Experiment"])
55
 
56
  if __name__ == "__main__":
57
  demo.launch()