Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,5 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from langchain.chains import LLMChain
|
| 3 |
-
from langchain.prompts import PromptTemplate
|
| 4 |
from langchain_huggingface import HuggingFaceEndpoint
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
llm1 = HuggingFaceEndpoint(model='t5-small')
|
| 10 |
-
llm2 = HuggingFaceEndpoint(model='t5-large')
|
| 11 |
-
|
| 12 |
-
# Define the agent functions
|
| 13 |
-
def agent1(query):
|
| 14 |
-
return f"Agent 1: {query}"
|
| 15 |
-
|
| 16 |
-
def agent2(query):
|
| 17 |
-
return f"Agent 2: {query}"
|
| 18 |
-
|
| 19 |
-
# Define the states
|
| 20 |
-
s1 = StateGraph("s1")
|
| 21 |
-
s2 = StateGraph("s2")
|
| 22 |
-
|
| 23 |
-
# Define the LLM chains
|
| 24 |
-
chain1 = LLMChain(llm=llm1, prompt=PromptTemplate(input_variables=["query"], template="You are in state s1. {{query}}"))
|
| 25 |
-
chain2 = LLMChain(llm=llm2, prompt=PromptTemplate(input_variables=["query"], template="You are in state s2. {{query}}"))
|
| 26 |
-
|
| 27 |
-
# Define the transition functions
|
| 28 |
-
def transition_s1(query):
|
| 29 |
-
output = chain1.invoke(query=query)
|
| 30 |
-
return agent1(output), s2
|
| 31 |
-
|
| 32 |
-
def transition_s2(query):
|
| 33 |
-
output = chain2.invoke(query=query)
|
| 34 |
-
return agent2(output), s1
|
| 35 |
-
|
| 36 |
-
# Define the respond function
|
| 37 |
-
def respond(input, history, current_state):
|
| 38 |
-
if current_state == s1:
|
| 39 |
-
response, next_state = transition_s1(input)
|
| 40 |
-
elif current_state == s2:
|
| 41 |
-
response, next_state = transition_s2(input)
|
| 42 |
-
history.append((input, response))
|
| 43 |
-
return history, next_state
|
| 44 |
-
|
| 45 |
-
# Create the Gradio interface
|
| 46 |
-
with gr.Blocks() as demo:
|
| 47 |
-
gr.Markdown("# Chatbot Interface")
|
| 48 |
-
chatbot_interface = gr.Chatbot()
|
| 49 |
-
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
| 50 |
-
submit_btn = gr.Button("Send")
|
| 51 |
-
#current_state = s1
|
| 52 |
-
|
| 53 |
-
# Define the behavior of the submit button
|
| 54 |
-
def submit_click(input, history):
|
| 55 |
-
nonlocal current_state
|
| 56 |
-
history, current_state = respond(input, history, current_state)
|
| 57 |
-
return history
|
| 58 |
-
|
| 59 |
-
submit_btn.click(
|
| 60 |
-
fn=submit_click,
|
| 61 |
-
inputs=[user_input, chatbot_interface],
|
| 62 |
-
outputs=chatbot_interface
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
# Launch the Gradio application
|
| 66 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain_huggingface import HuggingFaceEndpoint
|
| 2 |
+
llm = HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.3")
|
| 3 |
+
our_query = "What is the currency of India?"
|
| 4 |
+
completion= llm.invoke(our_query)
|
| 5 |
+
print(completion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|