Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728import gradio as grimport random as rdfrom huggingface_hub import InferenceClientclient = InferenceClient("Qwen/Qwen2.5-72B-Instruct")def respond (message, history):messages = [{"role": "system", "content": "You are a chatbot who is sassy and doesnt explain an anser unless someone asks twice."}]if history:messages.extend(history)messages.append({"role": "user", "content": message})response = ""for message in client.chat_completion(messages,max_tokens=500,temperature=0.2,top_p=0.9,stream=True):token = message.choices[0].delta.contentresponse += tokenyield responsechatbot = gr.ChatInterface(respond, type = "messages")chatbot.launch(debug=True)1234567891011121314151617181920212223242526272829303132333435363738import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch# Load the model and tokenizermodel_name = "Qwen/Qwen2.5-72B-Instruct"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)# Define the chat functiondef chatbot(input_text):inputs = tokenizer.encode(input_text, return_tensors="pt")outputs = model.generate(inputs, max_length=150, num_return_sequences=1)response = tokenizer.decode(outputs[0], skip_special_tokens=True)return response# Define the Gradio interfacecss = """.gradio-container {background-color: #8C9A61; /* Sage Green */font-family: 'Times New Roman', Times, serif;}"""iface = gr.Interface(fn=chatbot,inputs=gr.Textbox(label="You:"),outputs=gr.Textbox(label="Chatbot:"),title="Qwen Chatbot",description="A chatbot using the Qwen/Qwen2.5-72B-Instruct model.",css=css)# Launch the interfaceiface.launch()
app.py+34-24