Rajut commited on
Commit
8d9d71b
1 Parent(s): 3290dee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- import torch
4
  import csv
5
  import re
 
6
  import warnings
7
 
8
  warnings.filterwarnings("ignore")
@@ -14,18 +14,17 @@ MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that
14
  @@ Response
15
  """
16
 
17
- # Create a text generation pipeline using the Magicoder model, text-generation task, bfloat16 torch data type and auto device mapping.
18
- generator = pipeline(
19
- model="ise-uiuc/Magicoder-S-DS-6.7B",
20
- task="text-generation",
21
- torch_dtype=torch.bfloat16,
22
- device_map="auto",
23
- )
24
 
25
  # Function to generate response
26
  def generate_response(instruction):
27
  prompt = MAGICODER_PROMPT.format(instruction=instruction)
28
- result = generator(prompt, max_length=2048, num_return_sequences=1, temperature=0.0)
29
  response = result[0]["generated_text"]
30
  response_start_index = response.find("@@ Response") + len("@@ Response")
31
  response = response[response_start_index:].strip()
@@ -37,20 +36,14 @@ def save_to_csv(data, filename):
37
  writer = csv.writer(csvfile)
38
  writer.writerow(data)
39
 
40
- # Function to process user feedback
41
- def process_output(correct_output):
42
- if correct_output.lower() == 'yes':
43
- feedback = st.text_input("Do you want to provide any feedback?")
44
- save_to_csv(["Correct", feedback], 'output_ratings.csv')
45
- else:
46
- correct_code = st.text_area("Please enter the correct code:")
47
- feedback = st.text_input("Any other feedback you want to provide:")
48
- save_to_csv(["Incorrect", feedback, correct_code], 'output_ratings.csv')
49
-
50
  # Streamlit app
51
  def main():
 
52
  st.title("Magicoder Assistant")
53
 
 
 
 
54
  instruction = st.text_area("Enter your instruction here:")
55
  if st.button("Generate Response"):
56
  generated_response = generate_response(instruction)
@@ -58,7 +51,13 @@ def main():
58
  st.text(generated_response)
59
 
60
  correct_output = st.radio("Is the generated output correct?", ("Yes", "No"))
61
- process_output(correct_output)
 
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline
 
3
  import csv
4
  import re
5
+ import torch
6
  import warnings
7
 
8
  warnings.filterwarnings("ignore")
 
14
  @@ Response
15
  """
16
 
17
+ @st.cache(allow_output_mutation=True)
18
+ def load_model():
19
+ return pipeline(
20
+ model="ise-uiuc/Magicoder-S-DS-6.7B",
21
+ task="text-generation"
22
+ )
 
23
 
24
  # Function to generate response
25
  def generate_response(instruction):
26
  prompt = MAGICODER_PROMPT.format(instruction=instruction)
27
+ result = model(prompt, max_length=2048, num_return_sequences=1, temperature=0.0)
28
  response = result[0]["generated_text"]
29
  response_start_index = response.find("@@ Response") + len("@@ Response")
30
  response = response[response_start_index:].strip()
 
36
  writer = csv.writer(csvfile)
37
  writer.writerow(data)
38
 
 
 
 
 
 
 
 
 
 
 
39
  # Streamlit app
40
  def main():
41
+ global model
42
  st.title("Magicoder Assistant")
43
 
44
+ if 'model' not in globals():
45
+ model = load_model()
46
+
47
  instruction = st.text_area("Enter your instruction here:")
48
  if st.button("Generate Response"):
49
  generated_response = generate_response(instruction)
 
51
  st.text(generated_response)
52
 
53
  correct_output = st.radio("Is the generated output correct?", ("Yes", "No"))
54
+ if correct_output.lower() == 'yes':
55
+ feedback = st.text_input("Do you want to provide any feedback?")
56
+ save_to_csv(["Correct", feedback], 'output_ratings.csv')
57
+ else:
58
+ correct_code = st.text_area("Please enter the correct code:")
59
+ feedback = st.text_input("Any other feedback you want to provide:")
60
+ save_to_csv(["Incorrect", feedback, correct_code], 'output_ratings.csv')
61
 
62
  if __name__ == "__main__":
63
  main()