udayg01 commited on
Commit
260a7c3
·
1 Parent(s): fd88aab
Files changed (2) hide show
  1. app.py +131 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Mockinterview-Falcon.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1hCKPV5U_bg7QQXPUIwwDvCdB1N8fgz0z
8
+
9
+ ## Install dependencies
10
+ """
11
+
12
+
13
+ """## Import dependencies"""
14
+
15
+ import os
16
+ import torch
17
+ from transformers import (
18
+ AutoModelForCausalLM,
19
+ AutoTokenizer,
20
+ BitsAndBytesConfig,
21
+ pipeline
22
+ )
23
+
24
+ import csv
25
+ import codecs
26
+
27
+ from langchain import PromptTemplate, LLMChain
28
+ import random
29
+ import json
30
+
31
+ """## Creating pipeline for Falcon-7b"""
32
+
33
+ from langchain import HuggingFacePipeline
34
+ from transformers import AutoTokenizer, pipeline
35
+ import torch
36
+
37
+ model = "tiiuae/falcon-7b-instruct" #tiiuae/falcon-40b-instruct
38
+
39
+ tokenizer = AutoTokenizer.from_pretrained(model)
40
+
41
+ pipeline = pipeline(
42
+ "text-generation", #task
43
+ model=model,
44
+ tokenizer=tokenizer,
45
+ torch_dtype=torch.bfloat16,
46
+ trust_remote_code=True,
47
+ device_map="auto",
48
+ max_length=512,
49
+ do_sample=True,
50
+ top_k=10,
51
+ num_return_sequences=1,
52
+ eos_token_id=tokenizer.eos_token_id
53
+ )
54
+
55
+ llm = HuggingFacePipeline(pipeline = pipeline, model_kwargs = {'temperature':0})
56
+
57
+ """## Loading csv (attempting the program without RAG)
58
+
59
+ * RAG was reducing program efficiency.
60
+ """
61
+
62
+ file = "/content/Combined_Data_set.csv"
63
+
64
+ fields = []
65
+ rows = []
66
+
67
+ with codecs.open(file, 'r', 'utf-8') as csvfile:
68
+ csvreader = csv.reader(csvfile)
69
+ fields = next(csvreader)
70
+
71
+ for row in csvreader:
72
+ rows.append(row)
73
+
74
+ """## LLMChain for deciding next question"""
75
+
76
+ # Here we can make certain changes through the prompt template, like the tone in which we want the questions to be asked, we may use few shots for that.
77
+
78
+ record = random.randint(0,len(rows))
79
+
80
+ def get_question():
81
+ topic = rows[record][0] #extracting question from csv
82
+
83
+ template1 = """
84
+ You are a data science interviewer between an interview, ask a question regarding the following given topic:
85
+ Topic to ask question on as a interviewer: {question}
86
+ """
87
+ prompt1 = PromptTemplate(template=template1, input_variables=["question"])
88
+
89
+ llm_chain = LLMChain(prompt=prompt1, llm=llm)
90
+
91
+ next_question = llm_chain.run(topic)
92
+ # print(next_question)
93
+ json_string = "{{\"question\": \"{}\"}}".format(next_question)
94
+
95
+ json_ques = json.loads(json_string, strict=False)
96
+
97
+ return json_ques
98
+
99
+ result = get_question()
100
+ result
101
+
102
+ result['question']
103
+
104
+ """## LLMChain for evaluating user response"""
105
+
106
+ # Now we can improve performance through the prompt, like we can provide a few shots, tell it about how to give positive and negative responses using some shots.
107
+
108
+ # corr_ans = rows[record][1] #extracting answer from csv
109
+
110
+ def get_evaluation(response):
111
+ template2 = '''
112
+ You are a data scientist interviewer and you are taking the interview of someone.
113
+ Evaluate the response given by that person: {response}
114
+
115
+ '''
116
+ prompt2 = PromptTemplate(template=template2, input_variables=["response"])
117
+
118
+ llm_chain2 = LLMChain(prompt=prompt2, llm=llm)
119
+
120
+ evaluation = llm_chain2.run(response)
121
+ #print(evaluation)
122
+ json_string = "{{\"response\" : \"{}\" }}".format(evaluation)
123
+
124
+ json_eval = json.loads(json_string, strict=False)
125
+ return json_eval
126
+
127
+ response = input("Enter your response: ")
128
+ result = get_evaluation(response)
129
+ result
130
+
131
+ result['response']
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ einops
3
+ accelerate
4
+ langchain
5
+ bitsandbytes
6
+ uvicorn