Spaces:
Running
Running
Alanturner2
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from langchain_ai21 import ChatAI21
|
4 |
+
from ai21 import AI21Client
|
5 |
+
from ai21.models.chat import ChatMessage, DocumentSchema
|
6 |
+
|
7 |
+
# Set your AI21 API key
|
8 |
+
os.environ["AI21_API_KEY"] = "8T6NvXgGjhtlh9bh65jsNqb584BOorNM"
|
9 |
+
client = AI21Client(api_key="8T6NvXgGjhtlh9bh65jsNqb584BOorNM")
|
10 |
+
# Initialize the Jamba model
|
11 |
+
chatbot = ChatAI21(model="jamba-instruct", temperature=0.7)
|
12 |
+
|
13 |
+
# Define the function to handle chat
|
14 |
+
def chatbot_response(user_input):
|
15 |
+
# Wrap input into a dictionary with the expected format
|
16 |
+
messages = [ChatMessage(role='system', content='You are a concise factual based question answering assistant.'),
|
17 |
+
ChatMessage(role='user', content=user_input)
|
18 |
+
]
|
19 |
+
response = client.chat.completions.create(messages=messages,
|
20 |
+
model='jamba-1.5-large',
|
21 |
+
# max_tokens=4096,
|
22 |
+
# temperature=0.4,
|
23 |
+
# top_p=1.0,
|
24 |
+
# stop = [], ## ['####', '\n'],
|
25 |
+
# n=1,
|
26 |
+
# stream = False
|
27 |
+
)
|
28 |
+
return response.choices[0].message.content
|
29 |
+
# Create the Gradio interface
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=chatbot_response,
|
32 |
+
inputs="text",
|
33 |
+
outputs="text",
|
34 |
+
title="Jamba Chatbot",
|
35 |
+
description="A simple chatbot using AI21 Labs' Jamba technology."
|
36 |
+
)
|
37 |
+
|
38 |
+
# Launch the Gradio app
|
39 |
+
if __name__ == "__main__":
|
40 |
+
interface.launch()
|