Spaces:
Runtime error
Runtime error
File size: 1,851 Bytes
a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f a6ca64d 30f234f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import gradio as gr
import google.generativeai as palm
# Configure the API key
palm.configure(api_key='AIzaSyCi0mbXfp0uEBZpK7n-YnqR9tXT0tyXSM0')
# Get the model
models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
model_name = models[0].name # Assuming the first model supports text generation
# Define the prompt template
prompt_template = """
You are an expert at solving diet issues of people. Analyze the variable p and answer
whatever they ask, considering they are Indian. First, ask if they are vegetarian or non-vegetarian
and then answer according to their needs.
User question: {user_question}
Dietary preference: {diet_preference}
"""
# Function to generate a response
def generate_response(user_question, diet_preference):
prompt = prompt_template.format(
user_question=user_question,
diet_preference=diet_preference
)
completion = palm.generate_text(
model=model_name,
prompt=prompt,
max_length=200 # Adjust as per your requirement
)
return completion['text']
# Gradio Interface
def interface(user_question, diet_preference):
response = generate_response(user_question, diet_preference)
return response
# Set up Gradio interface components
question_input = gr.Textbox(label="Enter your question:")
diet_preference_input = gr.Radio(["Vegetarian", "Non-Vegetarian"], label="Select your dietary preference:")
output = gr.Textbox(label="Response:")
# Set up the Gradio interface layout
demo = gr.Interface(
fn=interface,
inputs=[question_input, diet_preference_input],
outputs=output,
title="Diet Doubt Solver ft.Versatile.ai",
description="Enter your diet-related question and get expert advice tailored to your dietary preference."
)
# Launch the demo
if __name__ == "__main__":
demo.launch()
|