File size: 6,234 Bytes
caa9340
 
 
 
 
 
9a1ecae
 
caa9340
 
9a1ecae
 
 
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0007861
caa9340
 
a621863
 
 
 
 
 
 
 
 
 
 
 
 
caa9340
 
 
 
 
f1166a4
 
 
 
caa9340
f1166a4
 
 
ac2e58a
caa9340
f1166a4
 
 
caa9340
 
f1166a4
caa9340
 
 
 
 
 
 
 
 
 
 
f1166a4
 
0007861
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0007861
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0007861
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0007861
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from ai71 import AI71
from PyPDF2 import PdfReader
from pdf2image import convert_from_path
import cv2
import numpy as np
import pytesseract
import subprocess
from PIL import Image
AI71_API_KEY = "api71-api-652e5c6c-8edf-41d0-9c34-28522b07bef9"

subprocess.run(['apt-get','update'])
subprocess.run(['apt-get','install','-y','tesseract-ocr'])

def extract_text_from_pdf(pdf_file):
    text = ""
    reader = PdfReader(pdf_file)
    for page in reader.pages:
        text += page.extract_text()
    return text

def generate_questions_from_text(text, no_of_questions, marks_per_part, no_parts):
    ai71 = AI71(AI71_API_KEY)
    messages = [
        {"role": "system", "content": "You are a teaching assistant"},
        {"role": "user",
         "content": f"Give your own {no_of_questions} questions under each part for {no_parts} parts with {marks_per_part} marks for each part. Note that all questions must be from the topics of {text}"}
    ]

    questions = []
    for chunk in ai71.chat.completions.create(
            model="tiiuae/falcon-180b-chat",
            messages=messages,
            stream=True,
    ):
        if chunk.choices[0].delta.content:
            questions.append(chunk.choices[0].delta.content)

    return "".join(questions)

def extract_text_from_image(image_path):
    # Load the image
    img = cv2.imread(image_path)

    # Ensure the image was loaded correctly
    if img is None:
        raise ValueError("Image not found or unable to load")

    # Convert the image to RGB format
    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    # Extract text from the image
    text = pytesseract.image_to_string(img_rgb)
    
    return text


def evaluate(question, answer, max_marks):
    prompt = f"""Questions: {question}
    Answer: {answer}.
    Evaluate answers strictly one by one(if there are multiple) for each question and assign marks out of {max_marks} based on below guidelines.
guidelines:
- If the answer is wrong or incorrect or irrelevent to topic, give 0 marks.

- If the answer is somewhat accurate, give total marks minus 2, and so on.
- If the answer is very accurate and complete, give total marks.
- If the answer is good but not completely accurate, give total marks minus 1.


Note:Provide only marks for each answers. dont provide anything other than that.
Format:
1.Question no: Marks,etc"""

    messages = [
        {"role": "system", "content": "You are a strict answer evaluator. "},
        {"role": "user", "content": prompt}
    ]

    response_content = ""
    for chunk in  AI71(AI71_API_KEY).chat.completions.create(
            model="tiiuae/falcon-180b-chat",
            messages=messages,
            stream=True
    ):
        if chunk.choices[0].delta.content:
            response_content += chunk.choices[0].delta.content
    print(response_content)

    return response_content

def generate_student_report(name, age, cgpa, course, assigned_test, ai_test, interests, difficulty, courses_taken):
    prompt = f"""
    Name: {name}
    Age: {age}
    CGPA: {cgpa}
    Course: {course}
    Assigned Test Score: {assigned_test}
    AI generated Test Score: {ai_test}
    Interests: {interests}
    Difficulty in: {difficulty}
    Courses Taken: {courses_taken}
    Use the above student data to generate a neat personalized report and suggested teaching methods."""

    client = AI71(AI71_API_KEY)

    response = client.chat.completions.create(
        model="tiiuae/falcon-180B-chat",
        messages=[
            {"role": "system", "content": "You are a student report generator."},
            {"role": "user", "content": prompt}
        ]
    )

    report = response.choices[0].message.content if response.choices and response.choices[
        0].message else "No report generated."
    print(report)

    return report
def generate_timetable_module(data,hours_per_day,days_per_week,semester_end_date,subjects):
    response = AI71(AI71_API_KEY).chat.completions.create(
            model="tiiuae/falcon-180B-chat",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": f"Create a timetable starting from Monday based on the following inputs:\n"
                                            f"- Number of hours per day: {hours_per_day}\n"
                                            f"- Number of days per week: {days_per_week}\n"
                                            f"- Semester end date: {semester_end_date}\n"
                                            f"- Subjects: {', '.join(subjects)}\n"}
            ]
        )

        # Access the response content correctly
    return( response.choices[0].message.content if response.choices and response.choices[0].message else "No timetable generated.")

def cluster_topics(academic_topics):
    prompt = (
            "Please cluster the following academic topics into their respective subjects such as Mathematics, Physics, etc.: "
            + ", ".join(academic_topics))
    response = ""
    for chunk in AI71(AI71_API_KEY).chat.completions.create(
            model="tiiuae/falcon-180b-chat",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt},
            ],
            stream=True,
    ):
        if chunk.choices[0].delta.content:
            response += chunk.choices[0].delta.content
    return response

def generate_timetable_weak(clustered_subjects, hours_per_day):
    prompt = (
        f"Using the following subjects and topics:\n{clustered_subjects}\n"
        f"Generate a special class timetable for {hours_per_day} hours per day.\n"
        f"Also provide reference books and methods to teach the slow learners for each subject"
    )
    response = ""
    for chunk in AI71(AI71_API_KEY).chat.completions.create(
            model="tiiuae/falcon-180b-chat",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt},
            ],
            stream=True,
    ):
        if chunk.choices[0].delta.content:
            response += chunk.choices[0].delta.content
    return response