Spaces:
Sleeping
Sleeping
import gradio as gr | |
from langchain.chains import LLMChain | |
from langchain_core.prompts import ( | |
ChatPromptTemplate, | |
HumanMessagePromptTemplate, | |
MessagesPlaceholder, | |
) | |
from langchain_core.messages import SystemMessage | |
from langchain.chains.conversation.memory import ConversationBufferWindowMemory | |
from langchain_groq import ChatGroq | |
# # Initialize the language model and memory | |
# llm = Groq(api_key="your_groq_api_key") | |
# memory = ConversationBufferMemory() | |
# # Define the conversation chain | |
# conversation = ConversationChain(llm=llm, memory=memory) | |
# Function to generate responses | |
def generate_response(user_input): | |
# response = conversation.run(user_input) | |
return user_input | |
# Define additional inputs and examples if needed | |
additional_inputs = [ | |
gr.Dropdown(choices=["llama-3.1-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it", "gemma-7b-it"], value="llama-3.1-70b-versatile", label="Model"), | |
gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."), | |
gr.Slider(minimum=1, maximum=8000, step=1, value=8000, label="Max Tokens", info="The maximum number of tokens that the model can process in a single response.<br>Maximums: 8k for gemma 7b it, gemma2 9b it, llama 7b & 70b, 32k for mixtral 8x7b, 132k for llama 3.1."), | |
gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Top P", info="A method of text generation where a model will only consider the most probable next tokens that make up the probability p."), | |
gr.Number(precision=0, value=0, label="Seed", info="A starting point to initiate generation, use 0 for random") | |
] | |
example1 = [ | |
["Who are you?"], | |
] | |
# Create the Gradio interface | |
interface = gr.ChatInterface( | |
fn=generate_response, | |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"), | |
additional_inputs=additional_inputs, | |
examples=example1, | |
cache_examples=False, | |
) | |
# Launch the app | |
interface.launch() | |