File size: 5,562 Bytes
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0007861
caa9340
 
 
 
 
 
 
12a66cc
caa9340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from ai71 import AI71
from PyPDF2 import PdfReader
from pdf2image import convert_from_path
import cv2
import numpy as np
import pytesseract
AI71_API_KEY = "api71-api-652e5c6c-8edf-41d0-9c34-28522b07bef9"

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):
    img = cv2.imread(image_path)
    text = pytesseract.image_to_string(img)
    return text





def evaluate(question, answer, max_marks):
    prompt = f"""Questions: {question}
    Answer: {answer}.


    Evaluate above questions one by one(if there are multiple) by provided answers and assign marks out of {max_marks}. No need overall score. Note that as maximum mark increases, the size of the answer must be large enough to get good marks. Give ouput in format below:
assigned marks: 
total marks: 
Note that you should not display total marks"""

    messages = [
        {"role": "system", "content": "You are an 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

    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