Spaces:
Sleeping
Sleeping
Add DeepSeek-R1 8B (Llama)
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from huggingface_hub import InferenceClient
|
|
10 |
|
11 |
HF_MODEL_MISTRAL = "mistralai/Mistral-7B-Instruct-v0.3"
|
12 |
HF_MODEL_LLAMA = "meta-llama/Llama-3.3-70B-Instruct"
|
|
|
13 |
|
14 |
UML_PROMPTS_DOC_URL = os.environ['UML_PROMPTS_DOC_URL']
|
15 |
ERD_PROMPTS_DOC_URL = os.environ['ERD_PROMPTS_DOC_URL']
|
@@ -77,7 +78,7 @@ def extract_plantuml_code(client_openai, uploaded_file, model_choice, prompts):
|
|
77 |
|
78 |
|
79 |
# Step 2: Compare PlantUML Code
|
80 |
-
def compare_plantuml(client_openai, client_hf_mistral, client_hf_llama, plantuml_instructor, plantuml_student, model_choice, prompts, diagram_type="UML"):
|
81 |
|
82 |
st.write("Model: ", model_choice)
|
83 |
|
@@ -118,6 +119,20 @@ def compare_plantuml(client_openai, client_hf_mistral, client_hf_llama, plantuml
|
|
118 |
temperature=0.2,
|
119 |
)
|
120 |
return response["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
else:
|
123 |
response = client_openai.chat.completions.create(
|
@@ -139,7 +154,7 @@ def compare_plantuml(client_openai, client_hf_mistral, client_hf_llama, plantuml
|
|
139 |
return response.choices[0].message.content
|
140 |
|
141 |
# Step 3A: Generate Student Feedback
|
142 |
-
def generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama, differences, model_choice, prompts):
|
143 |
|
144 |
st.write("Model (Student Feedback):", model_choice)
|
145 |
|
@@ -177,6 +192,20 @@ def generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama,
|
|
177 |
)
|
178 |
|
179 |
return response["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
else:
|
182 |
response = client_openai.chat.completions.create(
|
@@ -200,7 +229,7 @@ def generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama,
|
|
200 |
|
201 |
|
202 |
# Step 3B: Generate Educator Feedback
|
203 |
-
def generate_educator_feedback(client_openai, client_hf_mistral, client_hf_llama, differences, model_choice, prompts):
|
204 |
|
205 |
st.write("Model (Educator Feedback): ", model_choice)
|
206 |
|
@@ -238,6 +267,20 @@ def generate_educator_feedback(client_openai, client_hf_mistral, client_hf_llama
|
|
238 |
)
|
239 |
|
240 |
return response["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
else:
|
243 |
response = client_openai.chat.completions.create(
|
@@ -283,10 +326,11 @@ if openai_api_key and hf_api_key:
|
|
283 |
client_openai = OpenAI(api_key=openai_api_key)
|
284 |
client_hf_mistral = InferenceClient(model=HF_MODEL_MISTRAL, token=hf_api_key)
|
285 |
client_hf_llama = InferenceClient(model=HF_MODEL_LLAMA, token=hf_api_key)
|
|
|
286 |
|
287 |
model_choice_step1 = st.selectbox("Select the model for Step 1", ["gpt-4o", "gpt-4o-mini"])
|
288 |
-
model_choice_step2 = st.selectbox("Select the model for Step 2", [HF_MODEL_MISTRAL, HF_MODEL_LLAMA, "gpt-4o", "gpt-4o-mini"])
|
289 |
-
model_choice_step3 = st.selectbox("Select the model for Step 3", [HF_MODEL_MISTRAL, HF_MODEL_LLAMA, "gpt-4o", "gpt-4o-mini"])
|
290 |
|
291 |
st.subheader("Step 1: PlantUML Code Extraction using GPT-4o or GPT-4o Mini")
|
292 |
|
@@ -348,6 +392,7 @@ if openai_api_key and hf_api_key:
|
|
348 |
client_openai,
|
349 |
client_hf_mistral,
|
350 |
client_hf_llama,
|
|
|
351 |
plantuml_instructor_solution,
|
352 |
plantuml_student_solution,
|
353 |
model_choice_step2,
|
@@ -360,8 +405,8 @@ if openai_api_key and hf_api_key:
|
|
360 |
|
361 |
st.subheader("Step 3: Structured Feedback")
|
362 |
with st.spinner("Preparing structured feedback..."):
|
363 |
-
student_feedback = generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama, differences, model_choice_step3, prompts)
|
364 |
-
educator_feedback = generate_educator_feedback(client_openai, client_hf_mistral, client_hf_llama, differences, model_choice_step3, prompts)
|
365 |
|
366 |
col1, col2 = st.columns(2)
|
367 |
with col1:
|
|
|
10 |
|
11 |
HF_MODEL_MISTRAL = "mistralai/Mistral-7B-Instruct-v0.3"
|
12 |
HF_MODEL_LLAMA = "meta-llama/Llama-3.3-70B-Instruct"
|
13 |
+
HF_MODEL_DEEPSEEK = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
|
14 |
|
15 |
UML_PROMPTS_DOC_URL = os.environ['UML_PROMPTS_DOC_URL']
|
16 |
ERD_PROMPTS_DOC_URL = os.environ['ERD_PROMPTS_DOC_URL']
|
|
|
78 |
|
79 |
|
80 |
# Step 2: Compare PlantUML Code
|
81 |
+
def compare_plantuml(client_openai, client_hf_mistral, client_hf_llama, client_hf_deepseek, plantuml_instructor, plantuml_student, model_choice, prompts, diagram_type="UML"):
|
82 |
|
83 |
st.write("Model: ", model_choice)
|
84 |
|
|
|
119 |
temperature=0.2,
|
120 |
)
|
121 |
return response["choices"][0]["message"]["content"]
|
122 |
+
|
123 |
+
elif model_choice in [HF_MODEL_DEEPSEEK]:
|
124 |
+
response = client_hf_deepseek.chat_completion(
|
125 |
+
[
|
126 |
+
{
|
127 |
+
"role": "system",
|
128 |
+
"content": prompts[STEP2_SYSTEM_PROMPT],
|
129 |
+
},
|
130 |
+
{"role": "user", "content": user_prompt},
|
131 |
+
],
|
132 |
+
max_tokens=1024,
|
133 |
+
temperature=0.2,
|
134 |
+
)
|
135 |
+
return response["choices"][0]["message"]["content"]
|
136 |
|
137 |
else:
|
138 |
response = client_openai.chat.completions.create(
|
|
|
154 |
return response.choices[0].message.content
|
155 |
|
156 |
# Step 3A: Generate Student Feedback
|
157 |
+
def generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama, client_hf_deepseek, differences, model_choice, prompts):
|
158 |
|
159 |
st.write("Model (Student Feedback):", model_choice)
|
160 |
|
|
|
192 |
)
|
193 |
|
194 |
return response["choices"][0]["message"]["content"]
|
195 |
+
|
196 |
+
elif model_choice in [HF_MODEL_DEEPSEEK]:
|
197 |
+
response = client_hf_deepseek.chat_completion(
|
198 |
+
[
|
199 |
+
{
|
200 |
+
"role": "system",
|
201 |
+
"content": prompts[STEP2_SYSTEM_PROMPT],
|
202 |
+
},
|
203 |
+
{"role": "user", "content": user_prompt},
|
204 |
+
],
|
205 |
+
max_tokens=1024,
|
206 |
+
temperature=0.2,
|
207 |
+
)
|
208 |
+
return response["choices"][0]["message"]["content"]
|
209 |
|
210 |
else:
|
211 |
response = client_openai.chat.completions.create(
|
|
|
229 |
|
230 |
|
231 |
# Step 3B: Generate Educator Feedback
|
232 |
+
def generate_educator_feedback(client_openai, client_hf_mistral, client_hf_llama, client_hf_deepseek, differences, model_choice, prompts):
|
233 |
|
234 |
st.write("Model (Educator Feedback): ", model_choice)
|
235 |
|
|
|
267 |
)
|
268 |
|
269 |
return response["choices"][0]["message"]["content"]
|
270 |
+
|
271 |
+
elif model_choice in [HF_MODEL_DEEPSEEK]:
|
272 |
+
response = client_hf_deepseek.chat_completion(
|
273 |
+
[
|
274 |
+
{
|
275 |
+
"role": "system",
|
276 |
+
"content": prompts[STEP2_SYSTEM_PROMPT],
|
277 |
+
},
|
278 |
+
{"role": "user", "content": user_prompt},
|
279 |
+
],
|
280 |
+
max_tokens=1024,
|
281 |
+
temperature=0.2,
|
282 |
+
)
|
283 |
+
return response["choices"][0]["message"]["content"]
|
284 |
|
285 |
else:
|
286 |
response = client_openai.chat.completions.create(
|
|
|
326 |
client_openai = OpenAI(api_key=openai_api_key)
|
327 |
client_hf_mistral = InferenceClient(model=HF_MODEL_MISTRAL, token=hf_api_key)
|
328 |
client_hf_llama = InferenceClient(model=HF_MODEL_LLAMA, token=hf_api_key)
|
329 |
+
client_hf_deepseek = InferenceClient(model=HF_MODEL_DEEPSEEK, token=hf_api_key)
|
330 |
|
331 |
model_choice_step1 = st.selectbox("Select the model for Step 1", ["gpt-4o", "gpt-4o-mini"])
|
332 |
+
model_choice_step2 = st.selectbox("Select the model for Step 2", [HF_MODEL_MISTRAL, HF_MODEL_LLAMA, HF_MODEL_DEEPSEEK, "gpt-4o", "gpt-4o-mini"])
|
333 |
+
model_choice_step3 = st.selectbox("Select the model for Step 3", [HF_MODEL_MISTRAL, HF_MODEL_LLAMA, HF_MODEL_DEEPSEEK, "gpt-4o", "gpt-4o-mini"])
|
334 |
|
335 |
st.subheader("Step 1: PlantUML Code Extraction using GPT-4o or GPT-4o Mini")
|
336 |
|
|
|
392 |
client_openai,
|
393 |
client_hf_mistral,
|
394 |
client_hf_llama,
|
395 |
+
client_hf_deepseek
|
396 |
plantuml_instructor_solution,
|
397 |
plantuml_student_solution,
|
398 |
model_choice_step2,
|
|
|
405 |
|
406 |
st.subheader("Step 3: Structured Feedback")
|
407 |
with st.spinner("Preparing structured feedback..."):
|
408 |
+
student_feedback = generate_student_feedback(client_openai, client_hf_mistral, client_hf_llama, client_hf_deepseek, differences, model_choice_step3, prompts)
|
409 |
+
educator_feedback = generate_educator_feedback(client_openai, client_hf_mistral, client_hf_llama, client_hf_deepseek, differences, model_choice_step3, prompts)
|
410 |
|
411 |
col1, col2 = st.columns(2)
|
412 |
with col1:
|