-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoste.py
More file actions
689 lines (485 loc) · 20.3 KB
/
doste.py
File metadata and controls
689 lines (485 loc) · 20.3 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# -*- coding: utf-8 -*-
"""dostE
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1DNDp8X9pUiaxDedvQLchjxQ9zSxYsIFa
"""
!pip install git+https://github.com/huggingface/transformers torch accelerate bitsandbytes langchain
# Import libraries
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
from langchain.llms import HuggingFacePipeline
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
device = 'cuda' if torch.cuda.is_available() else 'cpu'
import subprocess
command = "pip install -U sentence-transformers chromadb"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
import transformers
from langchain.docstore.document import Document
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
# Download the Mistral 7B Instruct Model and Tokenizer
model_name = "bn22/Mistral-7B-Instruct-v0.1-sharded"
model = AutoModelForCausalLM.from_pretrained(model_name,load_in_4bit=True,torch_dtype=torch.bfloat16,quantization_config=bnb_config)
tokenizer = AutoTokenizer.from_pretrained(model_name)
"""Integrating the Model with LangChain
"""
# import transformers
#Create Text Generation Pipeline
text_generation_pipeline = transformers.pipeline(
model=model,
tokenizer=tokenizer,
task="text-generation",
temperature=0.2,
repetition_penalty=1.1,
return_full_text=True,
max_new_tokens=1000,
)
#Creating an LLM instance
mistral_llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
# Downloading embedding model
embedding_model = SentenceTransformerEmbeddings(model_name='BAAI/bge-large-zh-v1.5')
Sangam = """
Sangam serves as the conglomeration of all cultural clubs at the Institute,
making it one of the largest student-run teams in the Institute. Sangam
houses within it 16 different clubs, each catering to a unique and a niche art
form and audience. Together these clubs redefine the cultural landscape of
IIT Madras.
Cultural Contingent:
The Cultural Contingent of IIT Madras comprises the most talented and
skilled people in the various artforms we cater to. As a part of the
contingent, you represent IIT Madras in fests all around India, as well as in
Inter IIT.
Insti Radio:
Insti Radio is a newly launched initiative aimed at connecting the campus
in a unique, never-done-before way. There will be programs and fun
segments 24/7, so be sure to check it out!
CLUBS
Music Club:
The IITM Music Club conducts jam sessions, karaoke nights, open
mics, etc., generates content along with institute musicians and
helps to better the institute’s music scene. The club also
conducts the music events in Saarang and organises the
institute’s music festival Raagabop every year.
Drama Club:
Everyone needs some drama in their life. Come be a part of one
of the most happening clubs in insti! From Games After Dark,
(our initiator event) to Stage Design, to Scriptwriting, to
Stagecoach (our flagship event), the Drama Club has space for
all!
Join us as we celebrate over 60 years of existence and be
part of a the club that has nurtured many who went on to be
professional thespians!
Choreo Club:
Choreo Club is committed to uplift the dance culture in IITM. The
Choreo Club conducts Workshops catering to people belonging
to different proficiency levels throughout the semester. The club
believes dance is all about moving in joy and the better you
learn how to move the more joyful you become.
Classical Arts Club:
The Classical Arts Club plays a pivotal role in promoting and
supporting the classical arts within insti, be it the budding rasika
or the consummate vidvan. Over the past year, the CAC has
played host to artistes of renown like Nithyasree Mahadevan,
Leela Samson, Charumathi Raghuraman, and many more. It's
various educational and collaborative initiatives have been
much lauded, as it strives to be the one stop destination for all
classical art forms, being as inclusive as possible. As a hub to all
manifestations of the Classical arts, from appreciation to
performance, its activities are a rich addition to the insti cultural
scene.
Comedy Club:
Laugh, cry, spit and suffer.
Make jokes on your would-be lover.
We present The comedy club, boi
To mediocrity, say goodbye.
With events like stand up comedy, couch
potatoes, open mics, parody song, the
Comedy Club is sure to leave you in
splits!
Oratory Club:
Want to engage in passionate wars of words? Want to voice out and
justify radical stances? Want to move audience after audience with
your eloquent and persuasive speeches? Or charm them with your
brevity, wit, and humour? Fret not, for the Oratory Club is just the
place!
Word Games Club:
Do you flip to the last page of the newspaper everyday just to get to
the puzzle section? Ever noticed that ‘the Morse code’ rearranges to
‘here come dots’? Or ‘New York Times’ to ‘monkeys write’? Whether
you’re a Jack of all wordplay, a master of puns, a compulsive
anagrammer, or just someone who finds the antecedent verbosity
even remotely relatable, then this is the place to be :)
Writing Club:
Have you always been a bookworm, flipping through one book to
another with with ease? Are you a connoisseur of words, weaving
poetry and tales with ease? Are you someone bursting with stories to
tell, but don’t know where to start? The Writing Club is a community for
everyone, ranging from novices to professionals, poets to artists, and
readers to general enthu nuggets who want to explore all insti clubs!
Quiz Club:
One of the oldest clubs on campus, the IITM Quiz Club is one of the
best in the country.If trivia excites you, if you like to tickle your grey cells
by asking and answering questions, if you want to enjoy the thrill of
“cracking” a well-framed question, then QC is the place to be!
Media Club:
We are a group of enthusiastic people passionate about
photography , film-making . If you are someone who finds
capturing moments, telling stories and showing the world around
through your perspective, then this is the place to be! We at the
club enable you to pursue this art and have fun in the process
through a super exciting array of workshops, lectures, photo walks
with professionals to scenic places and competitive events.
Fine Arts Club:
Fine arts club is a club that primarily focuses on inculcating the
culture of art and its varied forms amongst the students through
its events and workshops. We believe that "Art makes you lose
yourself and find yourself at the same time".
Design&VFX Club:
Weaving technology with creativity, the Design and VFX Club
focuses on actualisation of creativity and through digital media
and tools. Hop on to our wagon to explore digital illustration,
graphic design, animation, UI/ UX, video editing and loads of other
cool stuff! (And discover the opportunities in those fields en route
xD)
Fashion Club:
Interested in Paris fashion week? Avid fashion lovers, here's Fashion
club for you. The club gives you an opportunity to be a part of
ramp walking workshops, modelling and other aspects of fashion.
Apart from this, the club also organises Mr and Miss Freshie ,
Unfold, and Panache, one of the Biggest fashion shows of India.
Culinary Arts Club:
Culinary Arts Club is the newest addition to the Sangam family! If
you're fascinated by Masterchef and love food, Culinary Arts Club
is the place to be! Help steer insti's food and cooking culture
through workshops, competitions, food fest, and more!
Informals Club:
Informals Club endeavours to bring
together insti through a variety of
fun and entertaining events throughout the
year. In a better world, you’d see
numerous Life-sized games at KV
grounds, the happy faces of people
playing amusing games near the
Carnival, and the intense Street sports
games happening around during Saarang, all thanks to us.
eSports Club:
Want to make your way in the fastest growing industry of the digital era?
The eSports club is the place to be- from streamers to professionals, we
have it all.
Be a part of the largest eSports event in South India or just
help your hostel survive in the midst of fierce interhostel rivalries. Watch
the best of the best compete or be one of them, one of the youngest and
the fastest growing club of the insti welcomes you.
Nova:
Ever thought being part of the biggest cosplay event in Chennai? Ever
thought which team brings up all the new events of Saarang? The
answer is Nova. If you want to be the part of the team which brings up
something new, exciting and quirky every year, join the ever-evolving
team of Saarang, Nova.
Spotlight:
Spotlight is the Saarang team which takes care of all the lecture series.
From GVM to the cast of Scam 1992i, Spotlight 2021 was power packed
with individuals from all walks of life. Previous speakers include Kamal
Hasan, Nawazuddin Siddiqui, Shashi Tharoor, Sid Sriram and many more.
By the end of Saarang your insta is going to be filled with your photos
with celebrities.
Meraki:
Meraki aims to bring you the unconventional at every Saarang. In 2020,
we had the Ferris wheel and the Columbus ride, the various inflatables at
KV and the Vintage Car Expo.In 2021, you would have been intrigued by
the Tatting workshop and amazed by the Whistling act, Carnatic fusion
act and the sand art act. In short, Meraki brings life to the streets of
Saarang and bling to your Saarang experience."""
LitSoc = """
Lit Soc is an epic year-long inter-hostel battle royale. All the hostels go
head to head over the course of the academic year and battle it out with
each other trying to win different competitions to get the necessary points
to take the Lit Soc cup home at the end of the year and be crowned
champions. The various events have different points and special points are
awarded to enthusiastic and talented freshers! Freshie events will also be
held towards the beginning of the odd semester to initiate them into Lit Soc
and give them a feel of how intense and enjoyable Lit Soc events can be. It
is a matter of great pride for hostel to win Lit Soc and as a resident of your
hostel; it will be up to you to help your hostel win it."""
Shaastra = """
IIT Madras hosts Shaastra, an annual technical event. True to its name,
Shaastra—the Sanskrit word for science—is a celebration of free thought
and a devotion to the engineering spirit. It offers the chance to get a
glimpse of the most cutting-edge technology that is currently popular all
over the world and is a melting pot of several scientific disciplines.
For the organizers and participants from various technical, scientific, and
management backgrounds, Shaastra has always been a very beneficial
learning experience. There is something for everyone, from schoolchildren
to university grads, academics to businesspeople, and engineers to
entrepreneurs. People who aren't ardent technophiles can benefit from
Shaastra as well. The fact that Drone Wars, Laser Shows, Fireworks displays,
and other events are regularly included in Shows and Exhibitions shows that
one need not always be an expert to appreciate what science is capable of.
Intense competitions, lectures, and a variety of educational courses
provided by Shaastra provide a stage for participants to demonstrate their
knowledge and enthusiasm. Watch out for competitions that put
contestants' mettle to the absolute limit, such as Fire and Ice, Shaastra
Junior Quiz, RoboWars, BrandWars, Hackathons, and others."""
director = """
Technical Society, IITM logo
HOMETEAMSCORINGBSCHOOLIHCHALL OF FAMEBLOGPROJECTSTECH MEETS
Co-Curricular Sphere, IIT Madras
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
The Technical Society, IITM
What I cannot build, I do not understand.
We fight. We build. We win. And eat pizza.
Since June, 2007
In 2007, a small group of highly ardent IIT Madras students found a team to inspire the emotion of building competent technology solutions to solve society's most problems, through a set of competitions & events
Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes ... the ones who see things differently -- they're not fond of rules, and they have no respect for the status quo. ... You can quote them, disagree with them, glorify or vilify them, but the only thing you can't do is ignore them because they change things.
The people who are crazy enough to think that they can change the world, are the ones who do.
Coverage
Latest updates from the team
Testimonials
What our benefactors say about us
img
I just began web development 3 days before the hackathon, and the experience was a huge leap. I learnt a lot in just the 24 hours.
Anshul Bagaria
09/05/2022
img
Trophies are won in the garage. They're simply picked at the podium
Navneeth (Raftar Captain 2019-21)
02/14/2022
img
TechSoc events are the most fun way to learn & bond with students over technology, while you're building together
Ankit Sanghvi (4th Year, BTech, Civil Engineering)
02/14/2022
img
TechSoc promotes a unique blend of competitive spirit between hostels, curiosity and a drive to learn more. We feel the drive to learn entirely new areas of technology in just a few days to give our hostel a competitive edge.
Prabhat B
09/05/2022
img
The TechSoc 24 Hour Hackathon was my first offline hacakthon, and the experience was entirely different from an online one. Surprisingly, it wasn't tiring at all - a couple of hours in class is usually tiring, but here I was able to go on for nearly 16 hours.
Sudip Mondal
09/05/2022
img
I just began web development 3 days before the hackathon, and the experience was a huge leap. I learnt a lot in just the 24 hours.
Anshul Bagaria
09/05/2022
img
Trophies are won in the garage. They're simply picked at the podium
Navneeth (Raftar Captain 2019-21)
02/14/2022
Our Partners
Patrons who've supported our legacy
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
TECHNICAL SOCIETY, IIT MADRAS
Sudha and Shankar Innovation Hub, Indian Institute of Technology, Madras.
CONTACT DETAILS
Prabhat - +91 91082 59723
Anouksha - +91 94978 44857
techsoc@smail.iitm.ac.in
QUICK LINKS
Home
Team
Scoring
Bschool
Ihc
Hall of fame
Blog
Projects
Tech meets
Copyright © 2023 All Rights Reserved by Technical Society, IIT Madras.
"""
buildschool = """
Technical Society, IITM logo
HOMETEAMSCORINGBSCHOOLIHCHALL OF FAMEBLOGPROJECTSTECH MEETS
Co-Curricular Sphere, IIT Madras
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Technical Society, IITM
Build School
Don't. Build. Alone.
Ok, but what is BuildSchool ?
Build sprint, lectures & products
BuildSchool is exactly what it claims to be - it helps you build products, starting from ground 0. In 10 weeks, 10 teams build 10 working prototypes with guidance from experts.
July-Nov'2023
Footprints in the sand
What I cannot create, I do not understand
Reference Links
What is BuildSchool
Application Guide
Sample Problem Statements
WhatsApp Group #1
WhatsApp Group #2
Coverage
Latest updates from the team
What's in it for you?
#dontbuildalone
💵 Prize money upto 10k
🍕 Group Office Hours
💪 A collaborative community of tinkerers
🧠 Guided workshops & QnA from the best minds in the industry
TECHNICAL SOCIETY, IIT MADRAS
Sudha and Shankar Innovation Hub, Indian Institute of Technology, Madras.
CONTACT DETAILS
Prabhat - +91 91082 59723
Anouksha - +91 94978 44857
techsoc@smail.iitm.ac.in
QUICK LINKS
Home
Team
Scoring
Bschool
Ihc
Hall of fame
Blog
Projects
Tech meets
Copyright © 2023 All Rights Reserved by Technical Society, IIT Madras.
Technical Society, IIT Madras
"""
#Chunck Documents
# Create Document object from text documents
docs = [Document(page_content=post) for post in [director, buildschool]]
# Split documents into chunks
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=500, chunk_overlap=10, separators=['\n\n', '\n', '.']
)
document_chunks = text_splitter.split_documents(docs)
#Initiate a Vector store Instance
# Initiate a chromadb instance
chroma_db = Chroma.from_documents(document_chunks, embedding_model)
retriever = chroma_db.as_retriever()
#Create Your Question Answering (QA) Chain
# Define an LLM here
# llm = OpenAI(temperature=0)
llm = mistral_llm
#option 2
# Prompt template
qa_template = """<s>[INST] You are a helpful assistant.
Use the following context to Answer the question below briefly:
{context}
{question} [/INST] </s>
"""
# Create a prompt instance
QA_PROMPT = PromptTemplate.from_template(qa_template)
# Custom QA Chain
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=retriever,
chain_type_kwargs={"prompt": QA_PROMPT}
)
# question = "what was your previous to previous answer"
# # Query Mistral 7B Instruct model
# response = qa_chain({"query": question})
# # Print your result
# print(response['result'])
"""---------------------end
Deploy the backend using pickle
"""
from google.colab import drive
drive.mount('/content/drive')
import torch
# Save your qa_chain model using torch.save
torch.save(model, "llm_model.pth")
import pickle
# Save your qa_chain to a file
with open("dost_model.pkl", "wb") as file:
pickle.dump(model, file)
# Define the desired path in Google Drive
desired_path = "/content/drive/MyDrive/dostE" # Replace with your Google Drive folder path
# MAKE SURE YOU HAVE ALREADY MOUNTED YOUR DRIVE IN STEP 6
# Copy your model file from the current path in Colab to the desired path in Google Drive
!cp qa_chain_model.pkl {desired_path}
!pip install flask
!pip install colabcode
!pip install fastapi
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['POST'])
def generate_response():
# Get the input data from the POST request
input_data = request.json
# Process the input data using your LLM model
response = qa_chain(input_data['What is techsoc?'])
# Return the response as JSON
return jsonify({"response": response})
if __name__ == '__main__':
app.run()
from colabcode import ColabCode
from fastapi import FastAPI
cc = ColabCode(port=12000, code=False)
app = FastAPI()
@app.get("/")
async def read_root():
return {"message": "Subscribe to @1littlecoder"}
cc.run_app(app=app)
import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pickle
iris = load_iris()
model = GaussianNB()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.1)
model_f = model.fit(X_train, y_train)
print("Model score: ", model.score(X_train, y_train))
print("Test Accuracy: ", model.score(X_test, y_test))
pickle.dump(model_f, open("model_gb.pkl", "wb"))
# Commented out IPython magic to ensure Python compatibility.
# %%writefile models.py
# from pydantic import BaseModel, conlist
# from typing import List
#
# class Iris(BaseModel):
# data: List[conlist(float, min_items=4, max_items=4)]
import pickle
import logging
from fastapi import FastAPI
from models import Iris
app = FastAPI(title="ML Models as API on Google Colab", description="with FastAPI and ColabCode", version="1.0")
# # Initialize logging
# my_logger = logging.getLogger()
# my_logger.setLevel(logging.DEBUG)
# logging.basicConfig(level=logging.DEBUG, filename='logs.log')
model = None
@app.on_event("startup")
def load_model():
global model
model = pickle.load(open("model_gb.pkl", "rb"))
@app.post("/api", tags=["prediction"])
async def get_predictions(iris: Iris):
try:
data = dict(iris)['data']
print(data)
iris_types = {
0: 'setosa',
1: 'versicolor',
2: 'virginica'
}
prediction = list(map(lambda x: iris_types[x], model.predict(data).tolist()))
log_proba = model.predict_log_proba(data).tolist()
return {"prediction": prediction, "log_proba": log_proba}
except:
my_logger.error("Something went wrong!")
return {"prediction": "error"}
cc.run_app(app=app)