Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from langchain_ai21 import ChatAI21
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
|
| 6 |
+
# 1. Set up your AI21 API key
|
| 7 |
+
os.environ["AI21_API_KEY"] = "your-ai21-api-key"
|
| 8 |
+
|
| 9 |
+
# 2. Create a prompt template for the chatbot
|
| 10 |
+
prompt = PromptTemplate(
|
| 11 |
+
input_variables=["user_input"],
|
| 12 |
+
template="""
|
| 13 |
+
You are a helpful and friendly chatbot. Respond concisely and informatively.
|
| 14 |
+
|
| 15 |
+
User: {user_input}
|
| 16 |
+
Chatbot:
|
| 17 |
+
"""
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
from langchain.memory import ConversationBufferMemory
|
| 22 |
+
|
| 23 |
+
memory = ConversationBufferMemory()
|
| 24 |
+
chat_chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
|
| 25 |
+
|
| 26 |
+
llm.streaming = True
|
| 27 |
+
|
| 28 |
+
import gradio as gr
|
| 29 |
+
|
| 30 |
+
def chatbot_response(user_input):
|
| 31 |
+
return chat_chain.run({"user_input": user_input})
|
| 32 |
+
|
| 33 |
+
gr.Interface(
|
| 34 |
+
fn=chatbot_response,
|
| 35 |
+
inputs="text",
|
| 36 |
+
outputs="text",
|
| 37 |
+
title="AI Chatbot with Jamba"
|
| 38 |
+
).launch()
|