Spaces:
Sleeping
Sleeping
Practice for Lesson 11 of Generative AI
Browse files123456789101112import gradio as grimport randomdef echo(message, history):choices = ["yes", "ummmmm no no no", "sure", ".....I think you need to rethink your choices", "you deserve a sweet treat", "I don't think so"]#use random to select one of these choicesrandom_message = random.choice(choices)return random_messagechatbot = gr.ChatInterface(echo, type = "messages", theme = "shivi/calm_seafoam")chatbot.launch()1234567891011121314151617181920212223242526272829import gradio as grimport randomfrom huggingface_hub import InferenceClientclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message, history):messages = ({"role": "system", "content": "You are a friendly chatbot."})if history:messages.extend(history)messages.append({"role": "user", "content" : message})response = client.chat_completion(messages, max_token = 100)print(response ["choices"][0]["message"]["content"].strip())return response ["choices"][0]["message"]["content"].strip()def echo(message, history):choices = ["yes", "ummmmm no no no", "sure", ".....I think you need to rethink your choices", "you deserve a sweet treat", "I don't think so"]#use random to select one of these choicesrandom_message = random.choice(choices)return random_messagechatbot = gr.ChatInterface(respond, type = "messages", theme = "shivi/calm_seafoam")chatbot.launch()
app.py+18-1