Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain import OpenAI, LLMChain
|
2 |
+
from langchain.agents import initialize_agent, Tool, ZeroShotAgent, AgentExecutor
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain.prompts.few_shot import FewShotPromptTemplate
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
"""# Space Implementation"""
|
8 |
+
|
9 |
+
clerkieExamples=["how do I use langchain?", "How do I create an agent with custom LLMChain?"]
|
10 |
+
|
11 |
+
import requests
|
12 |
+
import random
|
13 |
+
import gradio as gr
|
14 |
+
import openai
|
15 |
+
import re
|
16 |
+
|
17 |
+
|
18 |
+
def chat(message, history):
|
19 |
+
print(message)
|
20 |
+
history = history or []
|
21 |
+
endpoint = 'https://clerkie-langchain-server-bot.ishaan-jaff.repl.co/langchain_agent?user_query='
|
22 |
+
response = requests.get(endpoint + message).json()["response"]["output"]
|
23 |
+
# split on code
|
24 |
+
split_string = response.split("Code")
|
25 |
+
explanation = split_string[0]
|
26 |
+
history.append((message, explanation))
|
27 |
+
code_and_possible_links = "Code " + split_string[1]
|
28 |
+
|
29 |
+
if "Here is a list of documents that I viewed" in code_and_possible_links:
|
30 |
+
split_string = code_and_possible_links.split("Here")
|
31 |
+
code_sample = split_string[0]
|
32 |
+
history.append(("", code_sample))
|
33 |
+
relevant_links = "Here " + split_string[1]
|
34 |
+
history.append(("", relevant_links))
|
35 |
+
else:
|
36 |
+
history.append(("", code_and_possible_links))
|
37 |
+
return history, history
|
38 |
+
|
39 |
+
|
40 |
+
def set_text(inp):
|
41 |
+
return inp
|
42 |
+
|
43 |
+
def clear(arg):
|
44 |
+
return ""
|
45 |
+
|
46 |
+
with gr.Blocks(css=".gradio-container {background-color: #0d1116;}") as demo:
|
47 |
+
user_state=gr.State([])
|
48 |
+
gr.Markdown("""# Welcome to Clerkie LangChain 🤖""")
|
49 |
+
gr.Markdown("""Clerkie LangChain can answer questions about the langchain code repo""")
|
50 |
+
gr.Markdown("""### [clerkie.co](https://clerkie.co/)""")
|
51 |
+
with gr.Row():
|
52 |
+
with gr.Column():
|
53 |
+
output = gr.Chatbot().style(color_map=("orange", "green"))
|
54 |
+
inp = gr.Textbox(placeholder="Enter your question here")
|
55 |
+
print(type(inp))
|
56 |
+
btn = gr.Button("Send")
|
57 |
+
|
58 |
+
inp.submit(chat, [inp, user_state], [output, user_state])
|
59 |
+
inp.submit(clear, inp, inp)
|
60 |
+
btn.click(chat, [inp, user_state], [output, user_state])
|
61 |
+
btn.click(clear, inp, inp)
|
62 |
+
gr.Markdown("""### need help? got feedback? have thoughts? etc. ➜ Join the [Discord](https://discord.gg/KvG3azf39U)""")
|
63 |
+
gr.Examples(clerkieExamples,
|
64 |
+
inputs=inp,
|
65 |
+
cache_examples=False,
|
66 |
+
)
|
67 |
+
if __name__ == "__main__":
|
68 |
+
demo.launch(debug=True)
|