Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,32 +3,36 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
import google.generativeai as genai
|
| 5 |
|
| 6 |
-
# Configure API key
|
| 7 |
genai.configure(api_key='AIzaSyArybMiPDZARDCz7yZBjzEMx6zXgOXHtoc')
|
| 8 |
|
| 9 |
-
# Define the completion function
|
| 10 |
def get_completion(code_snippet):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Create the Gradio interface
|
| 34 |
iface = gr.Interface(
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import google.generativeai as genai
|
| 5 |
|
| 6 |
+
# Configure the API key
|
| 7 |
genai.configure(api_key='AIzaSyArybMiPDZARDCz7yZBjzEMx6zXgOXHtoc')
|
| 8 |
|
| 9 |
+
# Define the completion function with error handling
|
| 10 |
def get_completion(code_snippet):
|
| 11 |
+
try:
|
| 12 |
+
python_code_examples = """
|
| 13 |
+
---------------------
|
| 14 |
+
Example 1: x = 10 ... (Your code examples here)
|
| 15 |
+
---------------------
|
| 16 |
+
"""
|
| 17 |
+
prompt = f"""
|
| 18 |
+
Your task is to explain the following code snippet step-by-step:
|
| 19 |
+
{python_code_examples}
|
| 20 |
+
```
|
| 21 |
+
{code_snippet}
|
| 22 |
+
```
|
| 23 |
+
"""
|
| 24 |
|
| 25 |
+
# Generate content using the new API method
|
| 26 |
+
response = genai.generate_content(
|
| 27 |
+
prompt=prompt,
|
| 28 |
+
temperature=0,
|
| 29 |
+
max_output_tokens=500,
|
| 30 |
+
)
|
| 31 |
+
return response.text
|
| 32 |
|
| 33 |
+
except Exception as e:
|
| 34 |
+
# Return the error message
|
| 35 |
+
return f"An error occurred: {str(e)}"
|
| 36 |
|
| 37 |
# Create the Gradio interface
|
| 38 |
iface = gr.Interface(
|