Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines3456789101112131415161718192021222324252627282930313233342 unmodified linesimport gradio as grimport google.generativeai as genai# Configure API keygenai.configure(api_key='AIzaSyArybMiPDZARDCz7yZBjzEMx6zXgOXHtoc')# Define the completion function using the new API methodsdef get_completion(code_snippet):python_code_examples = """---------------------Example 1: x = 10 ... (your code examples)---------------------"""prompt = f"""Your task is to explain the following code snippet step-by-step:{python_code_examples}```{code_snippet}```"""# Generate text using the new methodresponse = genai.generate_content(prompt=prompt,temperature=0,max_output_tokens=500,)return response.text# Create the Gradio interfaceiface = gr.Interface(2 unmodified lines345678910111213141516171819202122232425262728293031323334353637382 unmodified linesimport gradio as grimport google.generativeai as genai# Configure the API keygenai.configure(api_key='AIzaSyArybMiPDZARDCz7yZBjzEMx6zXgOXHtoc')# Define the completion function with error handlingdef get_completion(code_snippet):try:python_code_examples = """---------------------Example 1: x = 10 ... (Your code examples here)---------------------"""prompt = f"""Your task is to explain the following code snippet step-by-step:{python_code_examples}```{code_snippet}```"""# Generate content using the new API methodresponse = genai.generate_content(prompt=prompt,temperature=0,max_output_tokens=500,)return response.textexcept Exception as e:# Return the error messagereturn f"An error occurred: {str(e)}"# Create the Gradio interfaceiface = gr.Interface(
app.py+25-21