-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.reader.py
More file actions
62 lines (45 loc) · 1.44 KB
/
code.reader.py
File metadata and controls
62 lines (45 loc) · 1.44 KB
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
59
60
61
# import os
# from dotenv import load_dotenv
# import google.generativeai as genai
# load_dotenv()
# genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
# model = genai.GenerativeModel('gemini-2.5-flash')
# def readcode(filepath):
# """Read code from a file."""
# try:
# with open(filepath, "r") as f:
# return f.read()
# except FileNotFoundError:
# print("❌ Error: code file not found.")
# exit(1)
# def coder(code):
# """Explain code, inputs, variables, expected output, and errors."""
# prompt = f"""
# You are a professional programming assistant.
# Given the following code, do the following:
# 1. List the language used
# 2. List the **Inputs** (if any).
# 3. List all **Variables** used and their purposes.
# 4. Give the **Expected Output** of the code.
# 5. If the code contains an **error**, specify the error and mention the line or part where it occurs.
# Code:
# {code}
# Your explanation should be structured as:
# - Which language
# - Input:
# - Variables:
# - Expected Output:
# - Errors (if any):
# """
# try:
# response = model.generate_content(prompt)
# return response.text
# except Exception as e:
# print(f" An error occurred: {e}")
# exit(1)
# if __name__ == "__main__":
# code_content = readcode("code.py")
# result = coder(code_content)
# print("\n🔍 Code Analysis 🔍\n")
# print("-" * 50)
# print(result)