tharun1507 commited on
Commit
5a6af41
·
verified ·
1 Parent(s): 4408f66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
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 using the new API methods
10
  def get_completion(code_snippet):
11
- python_code_examples = """
12
- ---------------------
13
- Example 1: x = 10 ... (your code examples)
14
- ---------------------
15
- """
16
- prompt = f"""
17
- Your task is to explain the following code snippet step-by-step:
18
- {python_code_examples}
19
- ```
20
- {code_snippet}
21
- ```
22
- """
 
23
 
24
- # Generate text using the new method
25
- response = genai.generate_content(
26
- prompt=prompt,
27
- temperature=0,
28
- max_output_tokens=500,
29
- )
 
30
 
31
- return response.text
 
 
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(