Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
from transformers import pipeline
|
|
|
4 |
import csv
|
5 |
import re
|
6 |
import warnings
|
@@ -14,17 +14,13 @@ MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that
|
|
14 |
@@ Response
|
15 |
"""
|
16 |
|
17 |
-
#
|
18 |
generator = pipeline(
|
19 |
model="ise-uiuc/Magicoder-S-DS-6.7B",
|
20 |
task="text-generation",
|
|
|
|
|
21 |
)
|
22 |
-
quantized_generator = torch.quantization.quantize_dynamic(
|
23 |
-
generator.model,
|
24 |
-
{torch.nn.Linear},
|
25 |
-
dtype=torch.qint8
|
26 |
-
)
|
27 |
-
generator.model = quantized_generator
|
28 |
|
29 |
# Function to generate response
|
30 |
def generate_response(instruction):
|
@@ -41,6 +37,16 @@ def save_to_csv(data, filename):
|
|
41 |
writer = csv.writer(csvfile)
|
42 |
writer.writerow(data)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Streamlit app
|
45 |
def main():
|
46 |
st.title("Magicoder Assistant")
|
@@ -52,13 +58,7 @@ def main():
|
|
52 |
st.text(generated_response)
|
53 |
|
54 |
correct_output = st.radio("Is the generated output correct?", ("Yes", "No"))
|
55 |
-
|
56 |
-
feedback = st.text_input("Do you want to provide any feedback?")
|
57 |
-
save_to_csv(["Correct", feedback], 'output_ratings.csv')
|
58 |
-
else:
|
59 |
-
correct_code = st.text_area("Please enter the correct code:")
|
60 |
-
feedback = st.text_input("Any other feedback you want to provide:")
|
61 |
-
save_to_csv(["Incorrect", feedback, correct_code], 'output_ratings.csv')
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
main()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
3 |
+
import torch
|
4 |
import csv
|
5 |
import re
|
6 |
import warnings
|
|
|
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):
|
|
|
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")
|
|
|
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()
|