Spaces:
Sleeping
Sleeping
Commit ·
fe711ab
1
Parent(s): 1877047
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from langchain.agents import load_tools
|
| 4 |
+
from langchain.agents import initialize_agent
|
| 5 |
+
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
|
| 6 |
+
from langchain.llms import OpenAI
|
| 7 |
+
|
| 8 |
+
def funct(sentence):
|
| 9 |
+
llm = OpenAI(temperature=0)
|
| 10 |
+
|
| 11 |
+
# Next, let's load some tools to use. Note that the `llm-math` tool uses an LLM, so we need to pass that in.
|
| 12 |
+
tools = load_tools(["serpapi", "llm-math"], llm=llm)
|
| 13 |
+
|
| 14 |
+
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
|
| 15 |
+
|
| 16 |
+
return agent.run(sentence)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as app:
|
| 20 |
+
sentence = gr.Textbox()
|
| 21 |
+
sentiment = gr.Label()
|
| 22 |
+
submit = gr.Button()
|
| 23 |
+
|
| 24 |
+
submit.click(fn=funct,
|
| 25 |
+
inputs=sentence,
|
| 26 |
+
outputs=sentiment)
|
| 27 |
+
|
| 28 |
+
app.launch(debug=True)
|