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

setting up MVP

Browse files
Files changed (2) hide show
  1. app.py +80 -14
  2. structured__apparatus_chain.py +0 -128
app.py CHANGED
@@ -1,22 +1,88 @@
1
  import gradio as gr
2
- from get_blender import main
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- main()
5
 
6
- def process_text(input_text):
7
- # Your processing logic here
8
- return input_text.upper()
 
 
9
 
10
- textbox = gr.Textbox(
11
- lines=5,
12
- placeholder="Type your text here...",
13
- interactive=False # Set this to False to hide the input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  )
15
 
16
- interface = gr.Interface(
17
- fn=process_text,
18
- inputs=textbox,
19
- outputs="text"
 
 
 
20
  )
21
 
22
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from structured_apparatus_chain import (
3
+ arxiv_chain as apparatus_arxiv_chain,
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,
31
+ "Wikipedia": apparatus_wikipedia_chain,
32
+ }
33
 
34
+ experiment_retriever_options = {
35
+ "Arxiv": experiment_arxiv_chain,
36
+ "PubMed": experiment_pub_med_chain,
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()
structured__apparatus_chain.py DELETED
@@ -1,128 +0,0 @@
1
- """
2
- #TODO: make a agent that uses HUMAMN as a tool to get:
3
- - Purpose of science experiment
4
- - What fields of study do they already know of
5
-
6
- #IDEA: Platform generate more indepth experiments by generaing a data set and generate / collect scienfic data
7
-
8
- ### Chatbot
9
- the chatbot helps the BOUNTY_BOARD_CHAIN generate science experiments
10
-
11
- ### EXPERIMENT and Provide feedback on experiments
12
-
13
- ### Interrgration
14
-
15
- - I need to intergrate this code into the app. This includes creating an id for each post, and potentially and a comment section for each "Experiment"
16
- - I addition i need to generate a mostly pinecone retriever to geenrate scientific experiments from the "community vectore search"
17
- - potentially have prenium users store their private data, but i may not implement this during the hackathon
18
- """
19
-
20
- # https://python.langchain.com/docs/modules/model_io/output_parsers/types/structured
21
- from langchain.output_parsers import ResponseSchema, StructuredOutputParser
22
- from langchain.prompts import PromptTemplate
23
- from langchain_openai import ChatOpenAI
24
- from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
25
- from langchain.memory import ConversationBufferMemory
26
- from langchain_core.runnables import RunnablePassthrough
27
- from langchain.retrievers import ArxivRetriever, pubmed
28
- from langchain_core.output_parsers import StrOutputParser
29
- from langchain.retrievers import ArxivRetriever
30
- from langchain.retrievers import PubMedRetriever
31
- from langchain.retrievers import WikipediaRetriever
32
- from operator import itemgetter
33
-
34
- # response_schemas = [
35
- # ResponseSchema(name="Experiment_Name", description="the name given to the experiment"),
36
- # ResponseSchema(name="Material", description="list of materials need to perfrom the experiments", type="list"),
37
- # ResponseSchema(name="Sources", description="list of sources where the information was retrievered from", type="list"),
38
- # ResponseSchema(name="Protocal", description="detailed instructions On how to make the item or perform the experiment", type="list"),
39
- # ResponseSchema(name="Fields_of_study", description="the fields of study that his experiment uses", type="list"),
40
- # ResponseSchema(name="Purpose_of_Experiments", description="assume what the user is trying to acchieve"),
41
- # ResponseSchema(name="Safety_Precuation", description="What does the User need to know to avoid any potential harm"),
42
- # ResponseSchema(name="Level_of_Difficulty", description="How difficult is it to perform this experiment ecample beginner, novice, Intermidiate, Hard "),
43
-
44
- # ]
45
-
46
- response_schemas = [
47
- ResponseSchema(name="Material", description="The base components needed to create this items from scratch DIY This item must be exact and not an estimation, also make sure each output has the obejcts name in context", type="list"),
48
- ResponseSchema(name="Fields_of_study", description="List the field of study this can be used for", type="list"),
49
- ]
50
-
51
- output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
52
-
53
- memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
54
-
55
- format_instructions = output_parser.get_format_instructions()
56
-
57
-
58
- prompt = maker_prompt = PromptTemplate(
59
- template="You must generate a well detailed list of items for creating a given item from scratch. \
60
- Also describe the purpose for a text-to-3d model to use for extra context\n{format_instructions}\n{question}\n{context}",
61
- input_variables=["question"],
62
- partial_variables={"format_instructions": format_instructions},
63
- memory = memory
64
- )
65
-
66
-
67
- def join_strings(*args: str) -> str:
68
- """
69
- Join an arbitrary number of strings into one string.
70
-
71
- Args:
72
- *args: Variable number of strings to join.
73
-
74
- Returns:
75
- str: Joined string.
76
- """
77
- return ''.join(args)
78
-
79
- def format_docs(docs):
80
- return "\n\n".join([join_strings(d.page_content, d.metadata['Entry ID'],d.metadata['Title'], ) for d in docs])
81
-
82
-
83
- arxiv_retriever = ArxivRetriever(load_max_docs=2)
84
-
85
- # model = ChatOpenAI(temperature=0)
86
- model = ChatOpenAI(temperature=0,model="gpt-4")
87
-
88
-
89
- retriver = arxiv_retriever = ArxivRetriever(load_max_docs=2)
90
-
91
- pub_med_retriever = PubMedRetriever()
92
-
93
- wikipedia_retriever = WikipediaRetriever()
94
-
95
- arxiv_chain = (
96
- {"context": arxiv_retriever, "question": RunnablePassthrough()}
97
- | prompt
98
- | model
99
- | output_parser
100
- )
101
-
102
- pub_med_chain = (
103
- {"context": pub_med_retriever, "question": RunnablePassthrough()}
104
- | prompt
105
- | model
106
- | output_parser
107
- )
108
-
109
- wikipedia_chain = (
110
- {"context": wikipedia_retriever, "question": RunnablePassthrough()}
111
- | prompt
112
- | model
113
- | output_parser
114
- )
115
-
116
-
117
-
118
-
119
- if __name__ == "__main__":
120
-
121
-
122
- # query = "how to create alectronoic on a cellulose subtstrate"
123
- query = "MicroScope"
124
- pub_med_data = pub_med_chain.invoke(query)
125
- wiki_data = wikipedia_chain.invoke(query)
126
-
127
- x=0
128
-