Spaces:
Build error
Build error
Update app.py
Browse files3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263643 unmodified lines"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})if val[1]:messages.append({"role": "assistant", "content": val[1]})messages.append({"role": "user", "content": message})response = ""for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(minimum=0.1,maximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)",),],)if __name__ == "__main__":demo.launch()3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839404142433 unmodified lines"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""# Load a pre-trained conversational AI model# This model can generate responses based on user inputschatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")# Customize the bot's knowledge base with predefined responsesfaq_responses = {"study tips": "Here are some study tips: 1) Break your study sessions into 25-minute chunks (Pomodoro Technique). 2) Test yourself frequently. 3) Stay organized using planners or apps like Notion or Todoist.","resources for studying": "You can find free study resources on websites like Khan Academy, Coursera, and edX. For research papers, check Google Scholar.","how to focus": "To improve focus, try studying in a quiet place, remove distractions like your phone, and use apps like Forest or Focus@Will.","time management tips": "Start by creating a to-do list each morning. Prioritize tasks using methods like Eisenhower Matrix and allocate specific time blocks for each task.","how to avoid procrastination": "Break tasks into smaller steps, set deadlines, and reward yourself after completing milestones. Tools like Trello can help you stay organized."}# Define the chatbot's response functiondef faq_chatbot(user_input):# Check if the user's input matches any FAQ keywordsfor key, response in faq_responses.items():if key in user_input.lower():return response# If no FAQ match, use the AI model to generate a responseconversation = chatbot(user_input)return conversation[0]['generated_text']# Create the Gradio interfaceinterface = gr.Interface(fn=faq_chatbot, # The function to handle user inputinputs=gr.Textbox(lines=2, placeholder="Ask me about studying tips or resources..."), # Input text boxoutputs="text", # Output as texttitle="Student FAQ Chatbot",description="Ask me for study tips, time management advice, or about resources to help with your studies!")# Launch the chatbotinterface.launch()
app.py+34-55