Sreekan commited on
Commit
c3be02c
·
verified ·
1 Parent(s): 87b0e6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -68
app.py CHANGED
@@ -64,74 +64,6 @@ demo = gr.ChatInterface(
64
  if __name__ == "__main__":
65
  demo.launch()
66
 
67
-
68
-
69
- import gradio as gr
70
- from langchain.chains import LLMChain
71
- from langchain.prompts import PromptTemplate
72
- from langchain_huggingface import HuggingFaceEndpoint
73
- from langgraph.graph import StateGraph
74
-
75
- # Define the LLM models
76
- llm1 = HuggingFaceEndpoint(model='t5-small')
77
- llm2 = HuggingFaceEndpoint(model='t5-large')
78
-
79
- # Define the agent functions
80
- def agent1(query):
81
- return f"Agent 1: {query}"
82
-
83
- def agent2(query):
84
- return f"Agent 2: {query}"
85
-
86
- # Define the states
87
- s1 = StateGraph("s1")
88
- s2 = StateGraph("s2")
89
-
90
- # Define the LLM chains
91
- chain1 = LLMChain(llm=llm1, prompt=PromptTemplate(input_variables=["query"], template="You are in state s1. {{query}}"))
92
- chain2 = LLMChain(llm=llm2, prompt=PromptTemplate(input_variables=["query"], template="You are in state s2. {{query}}"))
93
-
94
- # Define the transition functions
95
- def transition_s1(query):
96
- output = chain1.invoke(input=query)
97
- return agent1(output), s2
98
-
99
- def transition_s2(query):
100
- output = chain2.invoke(input=query)
101
- return agent2(output), s1
102
-
103
- # Define the respond function
104
- def respond(input, history, current_state):
105
- if current_state == s1:
106
- response, next_state = transition_s1(input)
107
- elif current_state == s2:
108
- response, next_state = transition_s2(input)
109
- history.append((input, response))
110
- return history, next_state
111
-
112
- # Create the Gradio interface
113
- current_state = s1 # Define current_state here
114
-
115
- with gr.Blocks() as demo:
116
- gr.Markdown("# Chatbot Interface")
117
- chatbot_interface = gr.Chatbot()
118
- user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
119
- submit_btn = gr.Button("Send")
120
-
121
- # Define the behavior of the submit button
122
- def submit_click(input, history):
123
- global current_state # Use global instead of nonlocal
124
- history, current_state = respond(input, history, current_state)
125
- return history
126
-
127
- submit_btn.click(
128
- fn=submit_click,
129
- inputs=[user_input, chatbot_interface],
130
- outputs=chatbot_interface
131
- )
132
-
133
- # Launch the Gradio application
134
- demo.launch()
135
  '''
136
 
137
  import gradio as gr
 
64
  if __name__ == "__main__":
65
  demo.launch()
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  '''
68
 
69
  import gradio as gr