Rohan Kataria commited on
Commit
df3e40f
·
2 Parent(s): d7cbf82 c9c9efe

Merge branch 'main' of https://huggingface.co/spaces/thewise/ConversationalChain

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .history/app_20230720012201.py +0 -105
  2. .history/app_20230720115617.py +0 -105
  3. .history/app_20230720115808.py +0 -165
  4. .history/app_20230720115842.py +0 -274
  5. .history/app_20230720120047.py +0 -116
  6. .history/app_20230720120625.py +0 -115
  7. .history/app_20230720120933.py +0 -60
  8. .history/app_20230720130430.py +0 -53
  9. .history/app_20230720130724.py +0 -53
  10. .history/app_20230720131115.py +0 -54
  11. .history/app_20230720131814.py +0 -55
  12. .history/app_20230720132136.py +0 -55
  13. .history/app_20230720132503.py +0 -55
  14. .history/app_20230720132518.py +0 -55
  15. .history/app_20230720133035.py +0 -60
  16. .history/app_20230720133118.py +0 -61
  17. .history/app_20230720133714.py +0 -61
  18. .history/app_20230720134604.py +0 -62
  19. .history/app_20230720135305.py +0 -62
  20. .history/app_20230720135438.py +0 -62
  21. .history/app_20230720135623.py +0 -62
  22. .history/app_20230720135741.py +0 -66
  23. .history/app_20230720140423.py +0 -64
  24. .history/app_20230720140424.py +0 -64
  25. .history/app_20230720141203.py +0 -66
  26. .history/app_20230720141228.py +0 -62
  27. .history/app_20230720141747.py +0 -62
  28. .history/app_20230720141944.py +0 -62
  29. .history/app_20230720142413.py +0 -70
  30. .history/app_20230720142550.py +0 -71
  31. .history/app_20230720142627.py +0 -71
  32. .history/app_20230720142635.py +0 -71
  33. .history/app_20230720142718.py +0 -69
  34. .history/app_20230720142924.py +0 -69
  35. .history/app_20230720143034.py +0 -68
  36. .history/app_20230720143041.py +0 -68
  37. .history/app_20230720143109.py +0 -68
  38. .history/app_20230720143123.py +0 -68
  39. .history/app_20230720143149.py +0 -68
  40. .history/app_20230720143312.py +0 -67
  41. .history/app_20230720143545.py +0 -72
  42. .history/app_20230720143613.py +0 -72
  43. .history/app_20230720143706.py +0 -61
  44. .history/app_20230720143740.py +0 -63
  45. .history/app_20230720143814.py +0 -63
  46. .history/app_20230720143901.py +0 -61
  47. .history/app_20230720144009.py +0 -61
  48. .history/app_20230720144049.py +0 -61
  49. .history/app_20230720144115.py +0 -61
  50. .history/src/main_20230720001200.py +0 -113
.history/app_20230720012201.py DELETED
@@ -1,105 +0,0 @@
1
- import os
2
- from threading import Lock
3
- import gradio as gr
4
- from typing import Any, Optional, Tuple
5
- from langchain.chains import ConversationChain
6
- from langchain.llms import OpenAI, HuggingFaceHub
7
-
8
-
9
- def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
10
- if chain_type == 'openai':
11
- os.environ["OPENAI_API_KEY"] = api_key
12
- llm = OpenAI(temperature=0)
13
- elif chain_type == 'falcon':
14
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
15
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
16
- else:
17
- print(f'Invalid chain_type: {chain_type}')
18
- return None
19
-
20
- chain = ConversationChain(llm=llm)
21
-
22
- # Unset the API keys
23
- os.environ.pop('OPENAI_API_KEY', None)
24
- os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
25
-
26
- return chain
27
-
28
-
29
- class ChatWrapper:
30
- def __init__(self, chain=None):
31
- self.chain = chain
32
- self.history = []
33
- self.lock = Lock()
34
-
35
- def __call__(self, inp: str):
36
- with self.lock:
37
- if self.chain is None:
38
- self.history.append((inp, "Please add your API key to proceed."))
39
- return self.history
40
-
41
- try:
42
- output = self.chain.run(input=inp)
43
- self.history.append((inp, output))
44
- except Exception as e:
45
- self.history.append((inp, f"An error occurred: {e}"))
46
-
47
- return self.history, self.history
48
-
49
-
50
- chat_wrapper = ChatWrapper()
51
-
52
- def update_chain(api_key: str, selection: str):
53
- global chat_wrapper
54
- chain = load_chain(chain_type=selection, api_key=api_key)
55
- chat_wrapper = ChatWrapper(chain=chain)
56
-
57
-
58
- def chat(message: str):
59
- global chat_wrapper
60
- return chat_wrapper(message)
61
-
62
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
63
-
64
- with block:
65
- with gr.Row():
66
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
67
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
68
- api_key_textbox = gr.Textbox(
69
- label="API Key",
70
- placeholder="Paste your API key",
71
- show_label=True,
72
- lines=1,
73
- type="password",
74
- )
75
-
76
- chatbot = gr.Chatbot()
77
-
78
- with gr.Row():
79
- message = gr.Textbox(
80
- label="Your Message",
81
- placeholder="Enter your message here",
82
- lines=1,
83
- )
84
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
85
-
86
- gr.Examples(
87
- examples=[
88
- "Hi! How's it going?",
89
- "What should I do tonight?",
90
- "Whats 2 + 2?",
91
- ],
92
- inputs=message,
93
- )
94
-
95
- gr.HTML("Demo application of a LangChain chain.")
96
-
97
- state = gr.State()
98
- agent_state = gr.State()
99
-
100
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
101
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
102
-
103
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
104
-
105
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720115617.py DELETED
@@ -1,105 +0,0 @@
1
- import os
2
- from threading import Lock
3
- import gradio as gr
4
- from typing import Any, Optional, Tuple
5
- from langchain.chains import ConversationChain
6
- from langchain.llms import OpenAI, HuggingFaceHub
7
-
8
-
9
- def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
10
- if chain_type == 'openai':
11
- os.environ["OPENAI_API_KEY"] = api_key
12
- llm = OpenAI(temperature=0)
13
- elif chain_type == 'falcon':
14
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
15
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
16
- else:
17
- print(f'Invalid chain_type: {chain_type}')
18
- return None
19
-
20
- chain = ConversationChain(llm=llm)
21
-
22
- # Unset the API keys
23
- os.environ.pop('OPENAI_API_KEY', None)
24
- os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
25
-
26
- return chain
27
-
28
-
29
- class ChatWrapper:
30
- def __init__(self, chain=None):
31
- self.chain = chain
32
- self.history = []
33
- self.lock = Lock()
34
-
35
- def __call__(self, inp: str):
36
- with self.lock:
37
- if self.chain is None:
38
- self.history.append((inp, "Please add your API key to proceed."))
39
- return self.history
40
-
41
- try:
42
- output = self.chain.run(input=inp)
43
- self.history.append((inp, output))
44
- except Exception as e:
45
- self.history.append((inp, f"An error occurred: {e}"))
46
-
47
- return self.history, self.history
48
-
49
-
50
- chat_wrapper = ChatWrapper()
51
-
52
- def update_chain(api_key: str, selection: str):
53
- global chat_wrapper
54
- chain = load_chain(chain_type=selection, api_key=api_key)
55
- chat_wrapper = ChatWrapper(chain=chain)
56
-
57
-
58
- def chat(message: str):
59
- global chat_wrapper
60
- return chat_wrapper(message)
61
-
62
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
63
-
64
- with block:
65
- with gr.Row():
66
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
67
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
68
- api_key_textbox = gr.Textbox(
69
- label="API Key",
70
- placeholder="Paste your API key",
71
- show_label=True,
72
- lines=1,
73
- type="password",
74
- )
75
-
76
- chatbot = gr.Chatbot()
77
-
78
- with gr.Row():
79
- message = gr.Textbox(
80
- label="Your Message",
81
- placeholder="Enter your message here",
82
- lines=1,
83
- )
84
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
85
-
86
- gr.Examples(
87
- examples=[
88
- "Hi! How's it going?",
89
- "What should I do tonight?",
90
- "Whats 2 + 2?",
91
- ],
92
- inputs=message,
93
- )
94
-
95
- gr.HTML("Demo application of a LangChain chain.")
96
-
97
- state = gr.State()
98
- agent_state = gr.State()
99
-
100
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
101
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
102
-
103
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
104
-
105
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720115808.py DELETED
@@ -1,165 +0,0 @@
1
- # import gradio as gr
2
- # from src.main import ChatWrapper
3
-
4
- # # Initialize an empty ChatWrapper initially
5
- # chat_wrapper = ChatWrapper(chain_type="openai", api_key="")
6
-
7
- # def update_chain(api_key_textbox, selection):
8
- # global chat_wrapper # We use the global chat_wrapper here
9
- # chat_wrapper = ChatWrapper(selection, api_key_textbox) # Re-initialize chat_wrapper
10
-
11
- # block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- # with block:
14
- # with gr.Row():
15
- # gr.Markdown("<h2><center>ConversationalChain App (+Model Selection)</center></h3>")
16
- # selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai", label_width="150px")
17
- # api_key_textbox = gr.Textbox(label="API Key", placeholder="Paste your API key", lines=1, type="password")
18
-
19
- # chatbot = gr.Chatbot()
20
-
21
- # with gr.Row():
22
- # message = gr.Textbox(label="What's your question?", placeholder="What's the answer to life, the universe, and everything?", lines=1)
23
- # submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
24
-
25
- # gr.Examples(examples=["Hi! How's it going?", "What should I do tonight?", "Whats 2 + 2?",], inputs=message)
26
- # gr.HTML("Demo application of a LangChain chain.")
27
-
28
- # state = gr.State()
29
- # agent_state = gr.State()
30
-
31
- # # Update the chat_wrapper when the API key or chain type is changed
32
- # api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
33
- # selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
34
-
35
- # # Modify the chat_wrapper to accept state and agent state, and to return a response and updated states
36
- # def chat(api_key, selection, message, state, agent_state):
37
- # print(f"chat called with api_key: {api_key}, selection: {selection}, message: {message}, state: {state}, agent_state: {agent_state}")
38
- # chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
39
- # history = chat_wrapper(message)
40
- # return history, state, agent_state
41
-
42
- # submit.click(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
43
- # message.submit(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
44
-
45
- # block.launch(debug=True)
46
-
47
-
48
-
49
-
50
- import os
51
- from typing import Any, Optional, Tuple
52
- from langchain.chains import ConversationChain
53
- from langchain.llms import HuggingFaceHub
54
- from langchain.llms import OpenAI
55
- from threading import Lock
56
- import gradio as gr
57
-
58
-
59
- def load_chain_openai(api_key: str):
60
- os.environ["OPENAI_API_KEY"] = api_key
61
- llm = OpenAI(temperature=0)
62
- chain = ConversationChain(llm=llm)
63
- os.environ["OPENAI_API_KEY"] = ""
64
- return chain
65
-
66
-
67
- def load_chain_falcon(api_key: str):
68
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
69
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
70
- chain = ConversationChain(llm=llm)
71
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
72
- return chain
73
-
74
-
75
- class ChatWrapper:
76
- def __init__(self, chain_type: str, api_key: str = ''):
77
- self.api_key = api_key
78
- self.chain_type = chain_type
79
- self.history = []
80
- self.lock = Lock()
81
-
82
- if self.api_key:
83
- if chain_type == 'openai':
84
- self.chain = load_chain_openai(self.api_key)
85
- elif chain_type == 'falcon':
86
- self.chain = load_chain_falcon(self.api_key)
87
- else:
88
- raise ValueError(f'Invalid chain_type: {chain_type}')
89
- else:
90
- self.chain = None
91
-
92
- def __call__(self, inp: str):
93
- self.lock.acquire()
94
- try:
95
- if self.chain is None:
96
- self.history.append((inp, "Please add your API key to proceed."))
97
- return self.history
98
-
99
- output = self.chain.run(input=inp)
100
- self.history.append((inp, output))
101
- except Exception as e:
102
- self.history.append((inp, f"An error occurred: {e}"))
103
- finally:
104
- self.lock.release()
105
-
106
- return self.history, self.history
107
-
108
-
109
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
110
-
111
- def update_chain(api_key: str, selection: str):
112
- global chat_wrapper
113
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
114
-
115
- def chat(message):
116
- global chat_wrapper
117
- chat_wrapper(message) # Get a response to the current message
118
- history = chat_wrapper.history # Access the entire chat history
119
- return history, history
120
-
121
-
122
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
123
-
124
- with block:
125
- with gr.Row():
126
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
127
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
128
- api_key_textbox = gr.Textbox(
129
- label="API Key",
130
- placeholder="Paste your OpenAI API key (sk-...)",
131
- show_label=True,
132
- lines=1,
133
- type="password",
134
- )
135
-
136
- chatbot = gr.Chatbot()
137
-
138
- with gr.Row():
139
- message = gr.Textbox(
140
- label="What's your question?",
141
- placeholder="What's the answer to life, the universe, and everything?",
142
- lines=1,
143
- )
144
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
145
-
146
- gr.Examples(
147
- examples=[
148
- "Hi! How's it going?",
149
- "What should I do tonight?",
150
- "Whats 2 + 2?",
151
- ],
152
- inputs=message,
153
- )
154
-
155
- gr.HTML("Demo application of a LangChain chain.")
156
-
157
- state = gr.State()
158
- agent_state = gr.State()
159
-
160
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
161
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
162
-
163
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
164
-
165
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720115842.py DELETED
@@ -1,274 +0,0 @@
1
- # import gradio as gr
2
- # from src.main import ChatWrapper
3
-
4
- # # Initialize an empty ChatWrapper initially
5
- # chat_wrapper = ChatWrapper(chain_type="openai", api_key="")
6
-
7
- # def update_chain(api_key_textbox, selection):
8
- # global chat_wrapper # We use the global chat_wrapper here
9
- # chat_wrapper = ChatWrapper(selection, api_key_textbox) # Re-initialize chat_wrapper
10
-
11
- # block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- # with block:
14
- # with gr.Row():
15
- # gr.Markdown("<h2><center>ConversationalChain App (+Model Selection)</center></h3>")
16
- # selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai", label_width="150px")
17
- # api_key_textbox = gr.Textbox(label="API Key", placeholder="Paste your API key", lines=1, type="password")
18
-
19
- # chatbot = gr.Chatbot()
20
-
21
- # with gr.Row():
22
- # message = gr.Textbox(label="What's your question?", placeholder="What's the answer to life, the universe, and everything?", lines=1)
23
- # submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
24
-
25
- # gr.Examples(examples=["Hi! How's it going?", "What should I do tonight?", "Whats 2 + 2?",], inputs=message)
26
- # gr.HTML("Demo application of a LangChain chain.")
27
-
28
- # state = gr.State()
29
- # agent_state = gr.State()
30
-
31
- # # Update the chat_wrapper when the API key or chain type is changed
32
- # api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
33
- # selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
34
-
35
- # # Modify the chat_wrapper to accept state and agent state, and to return a response and updated states
36
- # def chat(api_key, selection, message, state, agent_state):
37
- # print(f"chat called with api_key: {api_key}, selection: {selection}, message: {message}, state: {state}, agent_state: {agent_state}")
38
- # chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
39
- # history = chat_wrapper(message)
40
- # return history, state, agent_state
41
-
42
- # submit.click(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
43
- # message.submit(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
44
-
45
- # block.launch(debug=True)
46
-
47
-
48
-
49
-
50
- import os
51
- from typing import Any, Optional, Tuple
52
- from langchain.chains import ConversationChain
53
- from langchain.llms import HuggingFaceHub
54
- from langchain.llms import OpenAI
55
- from threading import Lock
56
- import gradio as gr
57
-
58
-
59
- def load_chain_openai(api_key: str):
60
- os.environ["OPENAI_API_KEY"] = api_key
61
- llm = OpenAI(temperature=0)
62
- chain = ConversationChain(llm=llm)
63
- os.environ["OPENAI_API_KEY"] = ""
64
- return chain
65
-
66
-
67
- def load_chain_falcon(api_key: str):
68
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
69
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
70
- chain = ConversationChain(llm=llm)
71
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
72
- return chain
73
-
74
-
75
- class ChatWrapper:
76
- def __init__(self, chain_type: str, api_key: str = ''):
77
- self.api_key = api_key
78
- self.chain_type = chain_type
79
- self.history = []
80
- self.lock = Lock()
81
-
82
- if self.api_key:
83
- if chain_type == 'openai':
84
- self.chain = load_chain_openai(self.api_key)
85
- elif chain_type == 'falcon':
86
- self.chain = load_chain_falcon(self.api_key)
87
- else:
88
- raise ValueError(f'Invalid chain_type: {chain_type}')
89
- else:
90
- self.chain = None
91
-
92
- def __call__(self, inp: str):
93
- self.lock.acquire()
94
- try:
95
- if self.chain is None:
96
- self.history.append((inp, "Please add your API key to proceed."))
97
- return self.history
98
-
99
- output = self.chain.run(input=inp)
100
- self.history.append((inp, output))
101
- except Exception as e:
102
- self.history.append((inp, f"An error occurred: {e}"))
103
- finally:
104
- self.lock.release()
105
-
106
- return self.history, self.history
107
-
108
-
109
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
110
-
111
- def update_chain(api_key: str, selection: str):
112
- global chat_wrapper
113
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
114
-
115
- def chat(message):
116
- global chat_wrapper
117
- chat_wrapper(message) # Get a response to the current message
118
- history = chat_wrapper.history # Access the entire chat history
119
- return history, history
120
-
121
-
122
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
123
-
124
- with block:
125
- with gr.Row():
126
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
127
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
128
- api_key_textbox = gr.Textbox(
129
- label="API Key",
130
- placeholder="Paste your OpenAI API key (sk-...)",
131
- show_label=True,
132
- lines=1,
133
- type="password",
134
- )
135
-
136
- chatbot = gr.Chatbot()
137
-
138
- with gr.Row():
139
- message = gr.Textbox(
140
- label="What's your question?",
141
- placeholder="What's the answer to life, the universe, and everything?",
142
- lines=1,
143
- )
144
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
145
-
146
- gr.Examples(
147
- examples=[
148
- "Hi! How's it going?",
149
- "What should I do tonight?",
150
- "Whats 2 + 2?",
151
- ],
152
- inputs=message,
153
- )
154
-
155
- gr.HTML("Demo application of a LangChain chain.")
156
-
157
- state = gr.State()
158
- agent_state = gr.State()
159
-
160
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
161
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
162
-
163
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
164
-
165
- block.launch(debug=True)
166
-
167
-
168
-
169
- # ######## old code
170
- # import os
171
- # from threading import Lock
172
- # import gradio as gr
173
- # from typing import Any, Optional, Tuple
174
- # from langchain.chains import ConversationChain
175
- # from langchain.llms import OpenAI, HuggingFaceHub
176
-
177
-
178
- # def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
179
- # if chain_type == 'openai':
180
- # os.environ["OPENAI_API_KEY"] = api_key
181
- # llm = OpenAI(temperature=0)
182
- # elif chain_type == 'falcon':
183
- # os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
184
- # llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
185
- # else:
186
- # print(f'Invalid chain_type: {chain_type}')
187
- # return None
188
-
189
- # chain = ConversationChain(llm=llm)
190
-
191
- # # Unset the API keys
192
- # os.environ.pop('OPENAI_API_KEY', None)
193
- # os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
194
-
195
- # return chain
196
-
197
-
198
- # class ChatWrapper:
199
- # def __init__(self, chain=None):
200
- # self.chain = chain
201
- # self.history = []
202
- # self.lock = Lock()
203
-
204
- # def __call__(self, inp: str):
205
- # with self.lock:
206
- # if self.chain is None:
207
- # self.history.append((inp, "Please add your API key to proceed."))
208
- # return self.history
209
-
210
- # try:
211
- # output = self.chain.run(input=inp)
212
- # self.history.append((inp, output))
213
- # except Exception as e:
214
- # self.history.append((inp, f"An error occurred: {e}"))
215
-
216
- # return self.history, self.history
217
-
218
-
219
- # chat_wrapper = ChatWrapper()
220
-
221
- # def update_chain(api_key: str, selection: str):
222
- # global chat_wrapper
223
- # chain = load_chain(chain_type=selection, api_key=api_key)
224
- # chat_wrapper = ChatWrapper(chain=chain)
225
-
226
-
227
- # def chat(message: str):
228
- # global chat_wrapper
229
- # return chat_wrapper(message)
230
-
231
- # block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
232
-
233
- # with block:
234
- # with gr.Row():
235
- # gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
236
- # selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
237
- # api_key_textbox = gr.Textbox(
238
- # label="API Key",
239
- # placeholder="Paste your API key",
240
- # show_label=True,
241
- # lines=1,
242
- # type="password",
243
- # )
244
-
245
- # chatbot = gr.Chatbot()
246
-
247
- # with gr.Row():
248
- # message = gr.Textbox(
249
- # label="Your Message",
250
- # placeholder="Enter your message here",
251
- # lines=1,
252
- # )
253
- # submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
254
-
255
- # gr.Examples(
256
- # examples=[
257
- # "Hi! How's it going?",
258
- # "What should I do tonight?",
259
- # "Whats 2 + 2?",
260
- # ],
261
- # inputs=message,
262
- # )
263
-
264
- # gr.HTML("Demo application of a LangChain chain.")
265
-
266
- # state = gr.State()
267
- # agent_state = gr.State()
268
-
269
- # submit.click(chat, inputs=[message], outputs=[chatbot, state])
270
- # message.submit(chat, inputs=[message], outputs=[chatbot, state])
271
-
272
- # api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
273
-
274
- # block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720120047.py DELETED
@@ -1,116 +0,0 @@
1
- import os
2
- from typing import Any, Optional, Tuple
3
- from langchain.chains import ConversationChain
4
- from langchain.llms import HuggingFaceHub
5
- from langchain.llms import OpenAI
6
- from threading import Lock
7
- import gradio as gr
8
-
9
-
10
- def load_chain_openai(api_key: str):
11
- os.environ["OPENAI_API_KEY"] = api_key
12
- llm = OpenAI(temperature=0)
13
- chain = ConversationChain(llm=llm)
14
- os.environ["OPENAI_API_KEY"] = ""
15
- return chain
16
-
17
-
18
- def load_chain_falcon(api_key: str):
19
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
20
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
21
- chain = ConversationChain(llm=llm)
22
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
23
- return chain
24
-
25
-
26
- class ChatWrapper:
27
- def __init__(self, chain_type: str, api_key: str = ''):
28
- self.api_key = api_key
29
- self.chain_type = chain_type
30
- self.history = []
31
- self.lock = Lock()
32
-
33
- if self.api_key:
34
- if chain_type == 'openai':
35
- self.chain = load_chain_openai(self.api_key)
36
- elif chain_type == 'falcon':
37
- self.chain = load_chain_falcon(self.api_key)
38
- else:
39
- raise ValueError(f'Invalid chain_type: {chain_type}')
40
- else:
41
- self.chain = None
42
-
43
- def __call__(self, inp: str):
44
- self.lock.acquire()
45
- try:
46
- if self.chain is None:
47
- self.history.append((inp, "Please add your API key to proceed."))
48
- return self.history
49
-
50
- output = self.chain.run(input=inp)
51
- self.history.append((inp, output))
52
- except Exception as e:
53
- self.history.append((inp, f"An error occurred: {e}"))
54
- finally:
55
- self.lock.release()
56
-
57
- return self.history, self.history
58
-
59
-
60
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
61
-
62
- def update_chain(api_key: str, selection: str):
63
- global chat_wrapper
64
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
65
-
66
- def chat(message):
67
- global chat_wrapper
68
- chat_wrapper(message) # Get a response to the current message
69
- history = chat_wrapper.history # Access the entire chat history
70
- return history, history
71
-
72
-
73
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
74
-
75
- with block:
76
- with gr.Row():
77
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
78
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
79
- api_key_textbox = gr.Textbox(
80
- label="API Key",
81
- placeholder="Paste your OpenAI API key (sk-...)",
82
- show_label=True,
83
- lines=1,
84
- type="password",
85
- )
86
-
87
- chatbot = gr.Chatbot()
88
-
89
- with gr.Row():
90
- message = gr.Textbox(
91
- label="What's your question?",
92
- placeholder="What's the answer to life, the universe, and everything?",
93
- lines=1,
94
- )
95
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
96
-
97
- gr.Examples(
98
- examples=[
99
- "Hi! How's it going?",
100
- "What should I do tonight?",
101
- "Whats 2 + 2?",
102
- ],
103
- inputs=message,
104
- )
105
-
106
- gr.HTML("Demo application of a LangChain chain.")
107
-
108
- state = gr.State()
109
- agent_state = gr.State()
110
-
111
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
112
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
113
-
114
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
115
-
116
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720120625.py DELETED
@@ -1,115 +0,0 @@
1
- import os
2
- from typing import Any, Optional, Tuple
3
- from langchain.chains import ConversationChain
4
- from langchain.llms import HuggingFaceHub
5
- from langchain.llms import OpenAI
6
- from threading import Lock
7
- import gradio as gr
8
-
9
-
10
- def load_chain_openai(api_key: str):
11
- os.environ["OPENAI_API_KEY"] = api_key
12
- llm = OpenAI(temperature=0)
13
- chain = ConversationChain(llm=llm)
14
- os.environ["OPENAI_API_KEY"] = ""
15
- return chain
16
-
17
-
18
- def load_chain_falcon(api_key: str):
19
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
20
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
21
- chain = ConversationChain(llm=llm)
22
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
23
- return chain
24
-
25
- class ChatWrapper:
26
- def __init__(self, chain_type: str, api_key: str = ''):
27
- self.api_key = api_key
28
- self.chain_type = chain_type
29
- self.history = []
30
- self.lock = Lock()
31
-
32
- if self.api_key:
33
- if chain_type == 'openai':
34
- self.chain = load_chain_openai(self.api_key)
35
- elif chain_type == 'falcon':
36
- self.chain = load_chain_falcon(self.api_key)
37
- else:
38
- raise ValueError(f'Invalid chain_type: {chain_type}')
39
- else:
40
- self.chain = None
41
-
42
- def __call__(self, inp: str):
43
- self.lock.acquire()
44
- try:
45
- if self.chain is None:
46
- self.history.append((inp, "Please add your API key to proceed."))
47
- return self.history
48
-
49
- output = self.chain.run(input=inp)
50
- self.history.append((inp, output))
51
- except Exception as e:
52
- self.history.append((inp, f"An error occurred: {e}"))
53
- finally:
54
- self.lock.release()
55
-
56
- return self.history, self.history
57
-
58
-
59
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
60
-
61
- def update_chain(api_key: str, selection: str):
62
- global chat_wrapper
63
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
64
-
65
- def chat(message):
66
- global chat_wrapper
67
- chat_wrapper(message) # Get a response to the current message
68
- history = chat_wrapper.history # Access the entire chat history
69
- return history, history
70
-
71
-
72
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
73
-
74
- with block:
75
- with gr.Row():
76
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
77
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
78
- api_key_textbox = gr.Textbox(
79
- label="API Key",
80
- placeholder="Paste your OpenAI API key (sk-...)",
81
- show_label=True,
82
- lines=1,
83
- type="password",
84
- )
85
-
86
- chatbot = gr.Chatbot()
87
-
88
- with gr.Row():
89
- message = gr.Textbox(
90
- label="What's your question?",
91
- placeholder="What's the answer to life, the universe, and everything?",
92
- lines=1,
93
- )
94
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
95
-
96
- gr.Examples(
97
- examples=[
98
- "Hi! How's it going?",
99
- "What should I do tonight?",
100
- "Whats 2 + 2?",
101
- ],
102
- inputs=message,
103
- )
104
-
105
- gr.HTML("Demo application of a LangChain chain.")
106
-
107
- state = gr.State()
108
- agent_state = gr.State()
109
-
110
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
111
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
112
-
113
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
114
-
115
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720120933.py DELETED
@@ -1,60 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat_wrapper
8
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
9
-
10
- def chat(message):
11
- global chat_wrapper
12
- chat_wrapper(message) # Get a response to the current message
13
- history = chat_wrapper.history # Access the entire chat history
14
- return history, history
15
-
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder="Paste your OpenAI API key (sk-...)",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("Demo application of a LangChain chain.")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
-
60
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720130430.py DELETED
@@ -1,53 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat_wrapper
8
- chat_wrapper = ChatWrapper(chain=selection, api_key=api_key)
9
-
10
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
11
-
12
- with block:
13
- with gr.Row():
14
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
15
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
16
- api_key_textbox = gr.Textbox(
17
- label="API Key",
18
- placeholder="Paste your OpenAI API key (sk-...)",
19
- show_label=True,
20
- lines=1,
21
- type="password",
22
- )
23
-
24
- chatbot = gr.Chatbot()
25
-
26
- with gr.Row():
27
- message = gr.Textbox(
28
- label="What's your question?",
29
- placeholder="What's the answer to life, the universe, and everything?",
30
- lines=1,
31
- )
32
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
33
-
34
- gr.Examples(
35
- examples=[
36
- "Hi! How's it going?",
37
- "What should I do tonight?",
38
- "Whats 2 + 2?",
39
- ],
40
- inputs=message,
41
- )
42
-
43
- gr.HTML("Demo application of a LangChain chain.")
44
-
45
- state = gr.State()
46
- agent_state = gr.State()
47
-
48
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
49
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
-
51
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
52
-
53
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720130724.py DELETED
@@ -1,53 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(chain=selection, api_key=api_key)
9
-
10
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
11
-
12
- with block:
13
- with gr.Row():
14
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
15
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
16
- api_key_textbox = gr.Textbox(
17
- label="API Key",
18
- placeholder="Paste your OpenAI API key (sk-...)",
19
- show_label=True,
20
- lines=1,
21
- type="password",
22
- )
23
-
24
- chatbot = gr.Chatbot()
25
-
26
- with gr.Row():
27
- message = gr.Textbox(
28
- label="What's your question?",
29
- placeholder="What's the answer to life, the universe, and everything?",
30
- lines=1,
31
- )
32
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
33
-
34
- gr.Examples(
35
- examples=[
36
- "Hi! How's it going?",
37
- "What should I do tonight?",
38
- "Whats 2 + 2?",
39
- ],
40
- inputs=message,
41
- )
42
-
43
- gr.HTML("Demo application of a LangChain chain.")
44
-
45
- state = gr.State()
46
- agent_state = gr.State()
47
-
48
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
49
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
-
51
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
52
-
53
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720131115.py DELETED
@@ -1,54 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(api_key=api_key, chain=selection)
9
-
10
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
11
-
12
- with block:
13
- with gr.Row():
14
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
15
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
16
- api_key_textbox = gr.Textbox(
17
- label="API Key",
18
- placeholder="Paste your OpenAI API key (sk-...)",
19
- show_label=True,
20
- lines=1,
21
- type="password",
22
- )
23
-
24
- chatbot = gr.Chatbot()
25
-
26
- with gr.Row():
27
- message = gr.Textbox(
28
- label="What's your question?",
29
- placeholder="What's the answer to life, the universe, and everything?",
30
- lines=1,
31
- )
32
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
33
-
34
- gr.Examples(
35
- examples=[
36
- "Hi! How's it going?",
37
- "What should I do tonight?",
38
- "Whats 2 + 2?",
39
- ],
40
- inputs=message,
41
- )
42
-
43
- gr.HTML("Demo application of a LangChain chain.")
44
-
45
- state = gr.State()
46
- agent_state = gr.State()
47
-
48
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
49
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
-
51
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
52
- selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
53
-
54
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720131814.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(api_key=api_key, chain=selection)
9
- return chat
10
-
11
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- with block:
14
- with gr.Row():
15
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
16
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
17
- api_key_textbox = gr.Textbox(
18
- label="API Key",
19
- placeholder="Paste your OpenAI API key (sk-...)",
20
- show_label=True,
21
- lines=1,
22
- type="password",
23
- )
24
-
25
- chatbot = gr.Chatbot()
26
-
27
- with gr.Row():
28
- message = gr.Textbox(
29
- label="What's your question?",
30
- placeholder="What's the answer to life, the universe, and everything?",
31
- lines=1,
32
- )
33
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
34
-
35
- gr.Examples(
36
- examples=[
37
- "Hi! How's it going?",
38
- "What should I do tonight?",
39
- "Whats 2 + 2?",
40
- ],
41
- inputs=message,
42
- )
43
-
44
- gr.HTML("Demo application of a LangChain chain.")
45
-
46
- state = gr.State()
47
- agent_state = gr.State()
48
-
49
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
51
-
52
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
53
- selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
54
-
55
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720132136.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(api_key=api_key, chain=selection)
9
- return chat
10
-
11
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- with block:
14
- with gr.Row():
15
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
16
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
17
- api_key_textbox = gr.Textbox(
18
- label="API Key",
19
- placeholder="Paste your OpenAI API key (sk-...)",
20
- show_label=True,
21
- lines=1,
22
- type="password",
23
- )
24
-
25
- chatbot = gr.Chatbot()
26
-
27
- with gr.Row():
28
- message = gr.Textbox(
29
- label="What's your question?",
30
- placeholder="What's the answer to life, the universe, and everything?",
31
- lines=1,
32
- )
33
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
34
-
35
- gr.Examples(
36
- examples=[
37
- "Hi! How's it going?",
38
- "What should I do tonight?",
39
- "Whats 2 + 2?",
40
- ],
41
- inputs=message,
42
- )
43
-
44
- gr.HTML("Demo application of a LangChain chain.")
45
-
46
- state = gr.State()
47
- agent_state = gr.State()
48
-
49
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
51
-
52
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
53
- selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
54
-
55
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720132503.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, message: str, state: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(api_key=api_key, input=message, history=state str, chain=selection)
9
- return chat
10
-
11
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- with block:
14
- with gr.Row():
15
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
16
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
17
- api_key_textbox = gr.Textbox(
18
- label="API Key",
19
- placeholder="Paste your OpenAI API key (sk-...)",
20
- show_label=True,
21
- lines=1,
22
- type="password",
23
- )
24
-
25
- chatbot = gr.Chatbot()
26
-
27
- with gr.Row():
28
- message = gr.Textbox(
29
- label="What's your question?",
30
- placeholder="What's the answer to life, the universe, and everything?",
31
- lines=1,
32
- )
33
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
34
-
35
- gr.Examples(
36
- examples=[
37
- "Hi! How's it going?",
38
- "What should I do tonight?",
39
- "Whats 2 + 2?",
40
- ],
41
- inputs=message,
42
- )
43
-
44
- gr.HTML("Demo application of a LangChain chain.")
45
-
46
- state = gr.State()
47
- agent_state = gr.State()
48
-
49
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
51
-
52
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
53
- selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
54
-
55
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720132518.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat = ChatWrapper()
5
-
6
- def update_chain(api_key: str, message: str, state: str, selection: str):
7
- global chat
8
- chat = ChatWrapper(api_key=api_key, input=message, history=state str, chain=selection)
9
- return chat
10
-
11
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
12
-
13
- with block:
14
- with gr.Row():
15
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
16
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
17
- api_key_textbox = gr.Textbox(
18
- label="API Key",
19
- placeholder="Paste your OpenAI API key (sk-...)",
20
- show_label=True,
21
- lines=1,
22
- type="password",
23
- )
24
-
25
- chatbot = gr.Chatbot()
26
-
27
- with gr.Row():
28
- message = gr.Textbox(
29
- label="What's your question?",
30
- placeholder="What's the answer to life, the universe, and everything?",
31
- lines=1,
32
- )
33
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
34
-
35
- gr.Examples(
36
- examples=[
37
- "Hi! How's it going?",
38
- "What should I do tonight?",
39
- "Whats 2 + 2?",
40
- ],
41
- inputs=message,
42
- )
43
-
44
- gr.HTML("Demo application of a LangChain chain.")
45
-
46
- state = gr.State()
47
- agent_state = gr.State()
48
-
49
- submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
50
- message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
51
-
52
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
53
- selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
54
-
55
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720133035.py DELETED
@@ -1,60 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat_wrapper
8
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
9
-
10
- def chat(message):
11
- global chat_wrapper
12
- chat_wrapper(message) # Get a response to the current message
13
- history = chat_wrapper.history # Access the entire chat history
14
- return history, history
15
-
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder="Paste your OpenAI API key (sk-...)",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("Demo application of a LangChain chain.")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
-
60
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720133118.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
5
-
6
- def update_chain(api_key: str, selection: str):
7
- global chat_wrapper
8
- chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return chat_wrapper # This is agent state
10
-
11
- def chat(message):
12
- global chat_wrapper
13
- chat_wrapper(message) # Get a response to the current message
14
- history = chat_wrapper.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("Demo application of a LangChain chain.")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720133714.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("Demo application of a LangChain chain.")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720134604.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.Markdown("<h3><center>Hello-World LangChain App</center></h3>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("Demo application of a LangChain chain.")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720135305.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.Markdown("<h2><center>ConversationalChain App 🤖</center></h2>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720135438.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720135623.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.Markdown("<h1><center>ConversationalChain App 🤖</center></h1>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720135741.py DELETED
@@ -1,66 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_label(api_key: str, selection: str):
18
- label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
19
- return {"markdown": label_text} #update the markdown
20
-
21
-
22
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
23
-
24
- with block:
25
- with gr.Row():
26
- gr.Markdown("<h1><center>ConversationalChain App 🤖</center></h1>")
27
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
28
- api_key_textbox = gr.Textbox(
29
- update_api_key_label,
30
- placeholder="Paste your OpenAI API key (sk-...)",
31
- show_label=True,
32
- lines=1,
33
- type="password",
34
- )
35
-
36
- chatbot = gr.Chatbot()
37
-
38
- with gr.Row():
39
- message = gr.Textbox(
40
- label="What's your question?",
41
- placeholder="What's the answer to life, the universe, and everything?",
42
- lines=1,
43
- )
44
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
45
-
46
- gr.Examples(
47
- examples=[
48
- "Hi! How's it going?",
49
- "What should I do tonight?",
50
- "Whats 2 + 2?",
51
- ],
52
- inputs=message,
53
- )
54
-
55
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
56
-
57
- state = gr.State()
58
- agent_state = gr.State()
59
-
60
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
61
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
62
-
63
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
64
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
-
66
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720140423.py DELETED
@@ -1,64 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
10
- return agent, {"markdown": label_text} # This is agent state
11
-
12
- def chat(message):
13
- global agent
14
- agent(message) # Get a response to the current message
15
- history = agent.history # Access the entire chat history
16
- return history, history # Return the history twice to update both the chatbot and the state
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- agent_api_label = gr.Markdown()
21
-
22
- with block:
23
- with gr.Row():
24
- gr.Markdown("<h1><center>ConversationalChain App 🤖</center></h1>")
25
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
26
- api_key_textbox = gr.Textbox(
27
- agent_api_label,
28
- placeholder="Paste your OpenAI API key (sk-...)",
29
- show_label=True,
30
- lines=1,
31
- type="password",
32
- )
33
-
34
- chatbot = gr.Chatbot()
35
-
36
- with gr.Row():
37
- message = gr.Textbox(
38
- label="What's your question?",
39
- placeholder="What's the answer to life, the universe, and everything?",
40
- lines=1,
41
- )
42
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
43
-
44
- gr.Examples(
45
- examples=[
46
- "Hi! How's it going?",
47
- "What should I do tonight?",
48
- "Whats 2 + 2?",
49
- ],
50
- inputs=message,
51
- )
52
-
53
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
54
-
55
- state = gr.State()
56
- agent_state = gr.State()
57
-
58
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
59
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
60
-
61
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
62
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state, agent_api_label])
63
-
64
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720140424.py DELETED
@@ -1,64 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
10
- return agent, {"markdown": label_text} # This is agent state
11
-
12
- def chat(message):
13
- global agent
14
- agent(message) # Get a response to the current message
15
- history = agent.history # Access the entire chat history
16
- return history, history # Return the history twice to update both the chatbot and the state
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- agent_api_label = gr.Markdown()
21
-
22
- with block:
23
- with gr.Row():
24
- gr.Markdown("<h1><center>ConversationalChain App 🤖</center></h1>")
25
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
26
- api_key_textbox = gr.Textbox(
27
- agent_api_label,
28
- placeholder="Paste your OpenAI API key (sk-...)",
29
- show_label=True,
30
- lines=1,
31
- type="password",
32
- )
33
-
34
- chatbot = gr.Chatbot()
35
-
36
- with gr.Row():
37
- message = gr.Textbox(
38
- label="What's your question?",
39
- placeholder="What's the answer to life, the universe, and everything?",
40
- lines=1,
41
- )
42
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
43
-
44
- gr.Examples(
45
- examples=[
46
- "Hi! How's it going?",
47
- "What should I do tonight?",
48
- "Whats 2 + 2?",
49
- ],
50
- inputs=message,
51
- )
52
-
53
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
54
-
55
- state = gr.State()
56
- agent_state = gr.State()
57
-
58
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
59
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
60
-
61
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
62
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state, agent_api_label])
63
-
64
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720141203.py DELETED
@@ -1,66 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- if selection == "falcon":
10
- api_key_textbox.placeholder = "Paste your Huggingface API key"
11
- else:
12
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
13
- return agent # This is agent state
14
-
15
- def chat(message):
16
- global agent
17
- agent(message) # Get a response to the current message
18
- history = agent.history # Access the entire chat history
19
- return history, history # Return the history twice to update both the chatbot and the state
20
-
21
-
22
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
23
-
24
- with block:
25
- with gr.Row():
26
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
27
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
28
- api_key_textbox = gr.Textbox(
29
- label="API Key",
30
- placeholder="Paste your OpenAI API key (sk-...)",
31
- show_label=True,
32
- lines=1,
33
- type="password",
34
- )
35
-
36
- chatbot = gr.Chatbot()
37
-
38
- with gr.Row():
39
- message = gr.Textbox(
40
- label="What's your question?",
41
- placeholder="What's the answer to life, the universe, and everything?",
42
- lines=1,
43
- )
44
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
45
-
46
- gr.Examples(
47
- examples=[
48
- "Hi! How's it going?",
49
- "What should I do tonight?",
50
- "Whats 2 + 2?",
51
- ],
52
- inputs=message,
53
- )
54
-
55
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
56
-
57
- state = gr.State()
58
- agent_state = gr.State()
59
-
60
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
61
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
62
-
63
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
64
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
-
66
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720141228.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720141747.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- # api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720141944.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
-
18
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
19
-
20
- with block:
21
- with gr.Row():
22
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
23
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
24
- api_key_textbox = gr.Textbox(
25
- label="API Key",
26
- placeholder="Paste your OpenAI API key (sk-...)",
27
- show_label=True,
28
- lines=1,
29
- type="password",
30
- )
31
-
32
- chatbot = gr.Chatbot()
33
-
34
- with gr.Row():
35
- message = gr.Textbox(
36
- label="What's your question?",
37
- placeholder="What's the answer to life, the universe, and everything?",
38
- lines=1,
39
- )
40
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
41
-
42
- gr.Examples(
43
- examples=[
44
- "Hi! How's it going?",
45
- "What should I do tonight?",
46
- "Whats 2 + 2?",
47
- ],
48
- inputs=message,
49
- )
50
-
51
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
52
-
53
- state = gr.State()
54
- agent_state = gr.State()
55
-
56
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
57
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
58
-
59
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
-
62
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142413.py DELETED
@@ -1,70 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
-
23
-
24
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
25
-
26
- with block:
27
- with gr.Row():
28
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
29
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
30
- # API_KEY_TEXTBOX if selection if Falcon then "HuggingFace API Key" else "OpenAI API Key
31
- api_key_textbox = gr.Textbox(
32
- label="API Key",
33
- placeholder="Paste your OpenAI API key (sk-...)",
34
- show_label=True,
35
- lines=1,
36
- type="password",
37
- )
38
-
39
- chatbot = gr.Chatbot()
40
-
41
- with gr.Row():
42
- message = gr.Textbox(
43
- label="What's your question?",
44
- placeholder="What's the answer to life, the universe, and everything?",
45
- lines=1,
46
- )
47
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
48
-
49
- gr.Examples(
50
- examples=[
51
- "Hi! How's it going?",
52
- "What should I do tonight?",
53
- "Whats 2 + 2?",
54
- ],
55
- inputs=message,
56
- )
57
-
58
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
59
-
60
- state = gr.State()
61
- agent_state = gr.State()
62
-
63
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
64
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
65
-
66
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
67
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
68
- selection.change(update_api_key_palceholder, inputs=[selection])
69
-
70
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142550.py DELETED
@@ -1,71 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
- return api_key_textbox.placeholder
23
-
24
-
25
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
26
-
27
- with block:
28
- with gr.Row():
29
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
30
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
31
- api_key_textbox = gr.Textbox(
32
- label="API Key",
33
- # Updating api_key_textbox placeholder based on selection
34
- placeholder=update_api_key_palceholder
35
- show_label=True,
36
- lines=1,
37
- type="password",
38
- )
39
-
40
- chatbot = gr.Chatbot()
41
-
42
- with gr.Row():
43
- message = gr.Textbox(
44
- label="What's your question?",
45
- placeholder="What's the answer to life, the universe, and everything?",
46
- lines=1,
47
- )
48
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
49
-
50
- gr.Examples(
51
- examples=[
52
- "Hi! How's it going?",
53
- "What should I do tonight?",
54
- "Whats 2 + 2?",
55
- ],
56
- inputs=message,
57
- )
58
-
59
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
60
-
61
- state = gr.State()
62
- agent_state = gr.State()
63
-
64
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
65
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
66
-
67
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
68
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
69
- selection.change(update_api_key_palceholder, inputs=[selection])
70
-
71
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142627.py DELETED
@@ -1,71 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
- return api_key_textbox.placeholder
23
-
24
-
25
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
26
-
27
- with block:
28
- with gr.Row():
29
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
30
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
31
- api_key_textbox = gr.Textbox(
32
- label="API Key",
33
- # Updating api_key_textbox placeholder based on selection
34
- placeholder= update_api_key_palceholder(),
35
- show_label=True,
36
- lines=1,
37
- type="password",
38
- )
39
-
40
- chatbot = gr.Chatbot()
41
-
42
- with gr.Row():
43
- message = gr.Textbox(
44
- label="What's your question?",
45
- placeholder="What's the answer to life, the universe, and everything?",
46
- lines=1,
47
- )
48
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
49
-
50
- gr.Examples(
51
- examples=[
52
- "Hi! How's it going?",
53
- "What should I do tonight?",
54
- "Whats 2 + 2?",
55
- ],
56
- inputs=message,
57
- )
58
-
59
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
60
-
61
- state = gr.State()
62
- agent_state = gr.State()
63
-
64
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
65
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
66
-
67
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
68
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
69
- selection.change(update_api_key_palceholder, inputs=[selection])
70
-
71
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142635.py DELETED
@@ -1,71 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
- return api_key_textbox.placeholder
23
-
24
-
25
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
26
-
27
- with block:
28
- with gr.Row():
29
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
30
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
31
- api_key_textbox = gr.Textbox(
32
- label="API Key",
33
- # Updating api_key_textbox placeholder based on selection
34
- placeholder= update_api_key_palceholder,
35
- show_label=True,
36
- lines=1,
37
- type="password",
38
- )
39
-
40
- chatbot = gr.Chatbot()
41
-
42
- with gr.Row():
43
- message = gr.Textbox(
44
- label="What's your question?",
45
- placeholder="What's the answer to life, the universe, and everything?",
46
- lines=1,
47
- )
48
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
49
-
50
- gr.Examples(
51
- examples=[
52
- "Hi! How's it going?",
53
- "What should I do tonight?",
54
- "Whats 2 + 2?",
55
- ],
56
- inputs=message,
57
- )
58
-
59
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
60
-
61
- state = gr.State()
62
- agent_state = gr.State()
63
-
64
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
65
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
66
-
67
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
68
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
69
- selection.change(update_api_key_palceholder, inputs=[selection])
70
-
71
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142718.py DELETED
@@ -1,69 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- # Updating api_key_textbox placeholder based on selection
32
- placeholder= update_api_key_palceholder,
33
- show_label=True,
34
- lines=1,
35
- type="password",
36
- )
37
-
38
- chatbot = gr.Chatbot()
39
-
40
- with gr.Row():
41
- message = gr.Textbox(
42
- label="What's your question?",
43
- placeholder="What's the answer to life, the universe, and everything?",
44
- lines=1,
45
- )
46
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
47
-
48
- gr.Examples(
49
- examples=[
50
- "Hi! How's it going?",
51
- "What should I do tonight?",
52
- "Whats 2 + 2?",
53
- ],
54
- inputs=message,
55
- )
56
-
57
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
58
-
59
- state = gr.State()
60
- agent_state = gr.State()
61
-
62
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
63
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
64
-
65
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
67
- selection.change(update_api_key_palceholder, inputs=[selection])
68
-
69
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720142924.py DELETED
@@ -1,69 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
- api_key_textbox.refresh()
23
-
24
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
25
-
26
- with block:
27
- with gr.Row():
28
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
29
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
30
- api_key_textbox = gr.Textbox(
31
- label="API Key",
32
- placeholder= "Paste your API key",
33
- show_label=True,
34
- lines=1,
35
- type="password",
36
- )
37
-
38
- chatbot = gr.Chatbot()
39
-
40
- with gr.Row():
41
- message = gr.Textbox(
42
- label="What's your question?",
43
- placeholder="What's the answer to life, the universe, and everything?",
44
- lines=1,
45
- )
46
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
47
-
48
- gr.Examples(
49
- examples=[
50
- "Hi! How's it going?",
51
- "What should I do tonight?",
52
- "Whats 2 + 2?",
53
- ],
54
- inputs=message,
55
- )
56
-
57
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
58
-
59
- state = gr.State()
60
- agent_state = gr.State()
61
-
62
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
63
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
64
-
65
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
67
- selection.change(update_api_key_palceholder, inputs=[selection])
68
-
69
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143034.py DELETED
@@ -1,68 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= "Paste your API key",
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_api_key_palceholder, inputs=[selection])
67
-
68
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143041.py DELETED
@@ -1,68 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= update_api_key_palceholder,
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_api_key_palceholder, inputs=[selection])
67
-
68
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143109.py DELETED
@@ -1,68 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= update_api_key_palceholder(selection.value),
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_api_key_palceholder, inputs=[selection])
67
-
68
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143123.py DELETED
@@ -1,68 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= update_api_key_palceholder(selection.value),
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- # selection.change(update_api_key_palceholder, inputs=[selection])
67
-
68
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143149.py DELETED
@@ -1,68 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= update_api_key_palceholder(selection.value),
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
- selection.change(update_api_key_palceholder, inputs=[selection])
67
-
68
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143312.py DELETED
@@ -1,67 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection: str):
18
- if selection == 'falcon':
19
- "Paste your HuggingFace API key hf_...)"
20
- else:
21
- "Paste your OpenAI API key (sk-...)"
22
-
23
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
24
-
25
- with block:
26
- with gr.Row():
27
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
28
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
29
- api_key_textbox = gr.Textbox(
30
- label="API Key",
31
- placeholder= update_api_key_palceholder(selection.value),
32
- show_label=True,
33
- lines=1,
34
- type="password",
35
- )
36
-
37
- chatbot = gr.Chatbot()
38
-
39
- with gr.Row():
40
- message = gr.Textbox(
41
- label="What's your question?",
42
- placeholder="What's the answer to life, the universe, and everything?",
43
- lines=1,
44
- )
45
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
46
-
47
- gr.Examples(
48
- examples=[
49
- "Hi! How's it going?",
50
- "What should I do tonight?",
51
- "Whats 2 + 2?",
52
- ],
53
- inputs=message,
54
- )
55
-
56
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
57
-
58
- state = gr.State()
59
- agent_state = gr.State()
60
-
61
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
62
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
63
-
64
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
65
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
66
-
67
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143545.py DELETED
@@ -1,72 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key (hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
-
23
- # Manually update the placeholder text in the HTML
24
- api_key_textbox.render()
25
-
26
-
27
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
28
-
29
- with block:
30
- with gr.Row():
31
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
32
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
33
- api_key_textbox = gr.Textbox(
34
- label="API Key",
35
- placeholder= "Paste Your API Key",
36
- show_label=True,
37
- lines=1,
38
- type="password",
39
- )
40
-
41
- chatbot = gr.Chatbot()
42
-
43
- with gr.Row():
44
- message = gr.Textbox(
45
- label="What's your question?",
46
- placeholder="What's the answer to life, the universe, and everything?",
47
- lines=1,
48
- )
49
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
50
-
51
- gr.Examples(
52
- examples=[
53
- "Hi! How's it going?",
54
- "What should I do tonight?",
55
- "Whats 2 + 2?",
56
- ],
57
- inputs=message,
58
- )
59
-
60
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
61
-
62
- state = gr.State()
63
- agent_state = gr.State()
64
-
65
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
66
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
67
-
68
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
69
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
70
- selection.change(update_api_key_palceholder, inputs=[selection])
71
-
72
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143613.py DELETED
@@ -1,72 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- def update_api_key_palceholder(selection):
18
- if selection == 'falcon':
19
- api_key_textbox.placeholder = "Paste your HuggingFace API key (hf_...)"
20
- else:
21
- api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
22
-
23
- # Manually update the placeholder text in the HTML
24
- return api_key_textbox.render()
25
-
26
-
27
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
28
-
29
- with block:
30
- with gr.Row():
31
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
32
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
33
- api_key_textbox = gr.Textbox(
34
- label="API Key",
35
- placeholder= "Paste Your API Key",
36
- show_label=True,
37
- lines=1,
38
- type="password",
39
- )
40
-
41
- chatbot = gr.Chatbot()
42
-
43
- with gr.Row():
44
- message = gr.Textbox(
45
- label="What's your question?",
46
- placeholder="What's the answer to life, the universe, and everything?",
47
- lines=1,
48
- )
49
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
50
-
51
- gr.Examples(
52
- examples=[
53
- "Hi! How's it going?",
54
- "What should I do tonight?",
55
- "Whats 2 + 2?",
56
- ],
57
- inputs=message,
58
- )
59
-
60
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
61
-
62
- state = gr.State()
63
- agent_state = gr.State()
64
-
65
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
66
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
67
-
68
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
69
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
70
- selection.change(update_api_key_palceholder, inputs=[selection])
71
-
72
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143706.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143740.py DELETED
@@ -1,63 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
- gr.HTML("For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
31
-
32
-
33
- chatbot = gr.Chatbot()
34
-
35
- with gr.Row():
36
- message = gr.Textbox(
37
- label="What's your question?",
38
- placeholder="What's the answer to life, the universe, and everything?",
39
- lines=1,
40
- )
41
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
42
-
43
- gr.Examples(
44
- examples=[
45
- "Hi! How's it going?",
46
- "What should I do tonight?",
47
- "Whats 2 + 2?",
48
- ],
49
- inputs=message,
50
- )
51
-
52
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
53
-
54
- state = gr.State()
55
- agent_state = gr.State()
56
-
57
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
58
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
59
-
60
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
62
-
63
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143814.py DELETED
@@ -1,63 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2>")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
- gr.HTML("For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
31
-
32
-
33
- chatbot = gr.Chatbot()
34
-
35
- with gr.Row():
36
- message = gr.Textbox(
37
- label="What's your question?",
38
- placeholder="What's the answer to life, the universe, and everything?",
39
- lines=1,
40
- )
41
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
42
-
43
- gr.Examples(
44
- examples=[
45
- "Hi! How's it going?",
46
- "What should I do tonight?",
47
- "Whats 2 + 2?",
48
- ],
49
- inputs=message,
50
- )
51
-
52
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
53
-
54
- state = gr.State()
55
- agent_state = gr.State()
56
-
57
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
58
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
59
-
60
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
61
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
62
-
63
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720143901.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2> <br> For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720144009.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2> <br> For <a href="https://huggingface.co/tiiuae/falcon-7b-instruct">Falcon</a> use HuggingFace API Token, for OpenAI use OpenAI API Key")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720144049.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2> <br> For <a href="https://huggingface.co/tiiuae">Falcon</a> use HuggingFace API Token, for OpenAI use OpenAI API Key")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/app_20230720144115.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from src.main import ChatWrapper
3
-
4
- agent = ChatWrapper('openai', '') # default agnet_state
5
-
6
- def update_agent(api_key: str, selection: str):
7
- global agent
8
- agent = ChatWrapper(chain_type=selection, api_key=api_key)
9
- return agent # This is agent state
10
-
11
- def chat(message):
12
- global agent
13
- agent(message) # Get a response to the current message
14
- history = agent.history # Access the entire chat history
15
- return history, history # Return the history twice to update both the chatbot and the state
16
-
17
- block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
18
-
19
- with block:
20
- with gr.Row():
21
- gr.HTML("<h2><center>ConversationalChain App 🤖</center></h2> <br> For <a href='https://huggingface.co/tiiuae/falcon-7b-instruct'>Falcon</a> use HuggingFace API Token, for OpenAI use OpenAI API Key")
22
- selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
23
- api_key_textbox = gr.Textbox(
24
- label="API Key",
25
- placeholder= "Paste Your API Key",
26
- show_label=True,
27
- lines=1,
28
- type="password",
29
- )
30
-
31
- chatbot = gr.Chatbot()
32
-
33
- with gr.Row():
34
- message = gr.Textbox(
35
- label="What's your question?",
36
- placeholder="What's the answer to life, the universe, and everything?",
37
- lines=1,
38
- )
39
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
40
-
41
- gr.Examples(
42
- examples=[
43
- "Hi! How's it going?",
44
- "What should I do tonight?",
45
- "Whats 2 + 2?",
46
- ],
47
- inputs=message,
48
- )
49
-
50
- gr.HTML("<center>View more at <a href='https://ai.rohankataria.com'>ai.rohankataria.com</a></center>")
51
-
52
- state = gr.State()
53
- agent_state = gr.State()
54
-
55
- submit.click(chat, inputs=[message], outputs=[chatbot, state])
56
- message.submit(chat, inputs=[message], outputs=[chatbot, state])
57
-
58
- api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
59
- selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
60
-
61
- block.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.history/src/main_20230720001200.py DELETED
@@ -1,113 +0,0 @@
1
- # import os
2
- # from typing import Any, Optional, Tuple
3
- # from langchain.chains import ConversationChain
4
- # from langchain.llms import HuggingFaceHub
5
- # from langchain.llms import OpenAI
6
- # from threading import Lock
7
-
8
-
9
- # def load_chain_openai(api_key: str):
10
- # os.environ["OPENAI_API_KEY"] = api_key # Setting up Key
11
- # llm = OpenAI(temperature=0)
12
- # chain = ConversationChain(llm=llm)
13
- # os.environ["OPENAI_API_KEY"] = "" # Unsetting Key to not leave the sensitive information needlessly in the environment
14
- # return chain
15
-
16
- # def load_chain_falcon(api_key: str):
17
- # os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key # Setting up Key
18
- # llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.5})
19
- # chain = ConversationChain(llm=llm)
20
- # os.environ["HUGGINGFACEHUB_API_TOKEN"] = "" # Unsetting Key to not leave the sensitive information needlessly in the environment
21
- # return chain
22
-
23
- # # Class for the Gradio app
24
- # class ChatWrapper:
25
- # def __init__(self, chain_type: str, api_key: str = ''):
26
- # self.api_key = api_key
27
- # self.chain_type = chain_type
28
- # self.history = []
29
- # self.lock = Lock()
30
-
31
- # if self.api_key:
32
- # if chain_type == 'openai':
33
- # self.chain = load_chain_openai(self.api_key)
34
- # elif chain_type == 'falcon':
35
- # self.chain = load_chain_falcon(self.api_key)
36
- # else:
37
- # raise ValueError(f'Invalid chain_type: {chain_type}')
38
- # else:
39
- # self.chain = None
40
-
41
- # def __call__(self, inp: str, chain: Optional[ConversationChain] = None):
42
- # try:
43
- # with self.lock:
44
- # if chain is not None:
45
- # self.chain = chain
46
- # elif self.chain is None:
47
- # self.history.append((inp, "Please add your API key to proceed."))
48
- # return self.history
49
-
50
- # output = self.chain.run(input=inp)
51
- # self.history.append((inp, output))
52
- # except Exception as e:
53
- # print(f"Error: {e}")
54
- # self.history.append((inp, f"An error occurred: {e}"))
55
-
56
- # return self.history
57
-
58
- import os
59
- from typing import Any, Optional, Tuple
60
- from langchain.chains import ConversationChain
61
- from langchain.llms import HuggingFaceHub
62
- from langchain.llms import OpenAI
63
- from threading import Lock
64
- import gradio as gr
65
-
66
-
67
- def load_chain_openai(api_key: str):
68
- os.environ["OPENAI_API_KEY"] = api_key
69
- llm = OpenAI(temperature=0)
70
- chain = ConversationChain(llm=llm)
71
- os.environ["OPENAI_API_KEY"] = ""
72
- return chain
73
-
74
-
75
- def load_chain_falcon(api_key: str):
76
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
77
- llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
78
- chain = ConversationChain(llm=llm)
79
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
80
- return chain
81
-
82
- class ChatWrapper:
83
- def __init__(self, chain_type: str, api_key: str = ''):
84
- self.api_key = api_key
85
- self.chain_type = chain_type
86
- self.history = []
87
- self.lock = Lock()
88
-
89
- if self.api_key:
90
- if chain_type == 'openai':
91
- self.chain = load_chain_openai(self.api_key)
92
- elif chain_type == 'falcon':
93
- self.chain = load_chain_falcon(self.api_key)
94
- else:
95
- raise ValueError(f'Invalid chain_type: {chain_type}')
96
- else:
97
- self.chain = None
98
-
99
- def __call__(self, inp: str):
100
- self.lock.acquire()
101
- try:
102
- if self.chain is None:
103
- self.history.append((inp, "Please add your API key to proceed."))
104
- return self.history
105
-
106
- output = self.chain.run(input=inp)
107
- self.history.append((inp, output))
108
- except Exception as e:
109
- self.history.append((inp, f"An error occurred: {e}"))
110
- finally:
111
- self.lock.release()
112
-
113
- return self.history, self.history