mrmarvelous/versatile_chatbot
0
1import gradio as gr2import google.generativeai as palm3 4# Configure the API key5palm.configure(api_key='AIzaSyCi0mbXfp0uEBZpK7n-YnqR9tXT0tyXSM0') 6 7# Get the model8models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]9model_name = models[0].name # Assuming the first model supports text generation10 11# Define the prompt template12prompt_template = """13You are an expert at solving diet issues of people. Analyze the variable p and answer14whatever they ask, considering they are Indian. First, ask if they are vegetarian or non-vegetarian15and then answer according to their needs.16 17User question: {user_question}18Dietary preference: {diet_preference}19"""20 21# Function to generate a response22def generate_response(user_question, diet_preference):23 prompt = prompt_template.format(24 user_question=user_question,25 diet_preference=diet_preference26 )27 28 completion = palm.generate_text(29 model=model_name,30 prompt=prompt,31 max_length=200 # Adjust as per your requirement32 )33 34 return completion['text']35 36# Gradio Interface37def interface(user_question, diet_preference):38 response = generate_response(user_question, diet_preference)39 return response40 41# Set up Gradio interface components42question_input = gr.Textbox(label="Enter your question:")43diet_preference_input = gr.Radio(["Vegetarian", "Non-Vegetarian"], label="Select your dietary preference:")44output = gr.Textbox(label="Response:")45 46# Set up the Gradio interface layout47demo = gr.Interface(48 fn=interface,49 inputs=[question_input, diet_preference_input],50 outputs=output,51 title="Diet Doubt Solver ft.Versatile.ai",52 description="Enter your diet-related question and get expert advice tailored to your dietary preference."53)54 55# Launch the demo56if __name__ == "__main__":57 demo.launch()58 