Yaswanth sai commited on
Commit
bb9e27e
·
1 Parent(s): e0ab78e

changed the que

Browse files
Files changed (1) hide show
  1. app.py +25 -37
app.py CHANGED
@@ -17,7 +17,7 @@ base_model = AutoModelForCausalLM.from_pretrained(
17
  MODEL_NAME,
18
  trust_remote_code=True,
19
  device_map="auto",
20
- torch_dtype=torch.float32 # Changed from float16 to float32 for better compatibility
21
  )
22
 
23
  print("Loading fine-tuned model...")
@@ -32,40 +32,22 @@ def generate_response(task_description, code_snippet, request_type, mode="concis
32
  try:
33
  # Format the prompt based on request type
34
  if request_type == "hint":
35
- prompt = f"""Task Description: {task_description}
36
-
37
- User's Code:
38
- {code_snippet}
39
-
40
- AI-HR Assistant: Here's a hint to help you:
41
- HINT:"""
42
  elif request_type == "feedback":
43
- prompt = f"""Task Description: {task_description}
44
-
45
- User's Code:
46
- {code_snippet}
47
-
48
- AI-HR Assistant: Here's my feedback on your code:
49
- FEEDBACK:"""
50
  else: # follow-up
51
- prompt = f"""Task Description: {task_description}
52
-
53
- User's Code:
54
- {code_snippet}
55
-
56
- AI-HR Assistant: Here's a follow-up question to extend your learning:
57
- FOLLOW-UP:"""
58
-
59
- # Generate response
60
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
61
- with torch.no_grad():
62
- outputs = model.generate(
63
- **inputs,
64
- max_new_tokens=256 if mode == "detailed" else 128,
65
- do_sample=True,
66
- temperature=0.7,
67
- top_p=0.95,
68
- )
69
 
70
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
71
 
@@ -81,7 +63,7 @@ FOLLOW-UP:"""
81
  except Exception as e:
82
  return f"An error occurred: {str(e)}"
83
 
84
- # Create Gradio interface
85
  with gr.Blocks(title="Live Coding HR Assistant") as demo:
86
  gr.Markdown("# 💻 Live Coding HR Assistant")
87
  gr.Markdown("Get hints, feedback, and follow-up questions for your coding tasks!")
@@ -120,9 +102,15 @@ with gr.Blocks(title="Live Coding HR Assistant") as demo:
120
  submit_btn.click(
121
  fn=generate_response,
122
  inputs=[task_description, code_snippet, request_type, mode],
123
- outputs=output
 
 
 
124
  )
125
 
126
- # Launch the app
127
- if __name__ == "__main__":
128
- demo.launch()
 
 
 
 
17
  MODEL_NAME,
18
  trust_remote_code=True,
19
  device_map="auto",
20
+ torch_dtype=torch.float32
21
  )
22
 
23
  print("Loading fine-tuned model...")
 
32
  try:
33
  # Format the prompt based on request type
34
  if request_type == "hint":
35
+ prompt = f"Task: {task_description}\nCode:\n{code_snippet}\nHINT:"
 
 
 
 
 
 
36
  elif request_type == "feedback":
37
+ prompt = f"Task: {task_description}\nCode:\n{code_snippet}\nFEEDBACK:"
 
 
 
 
 
 
38
  else: # follow-up
39
+ prompt = f"Task: {task_description}\nCode:\n{code_snippet}\nFOLLOW-UP:"
40
+
41
+ # Encode and generate
 
 
 
 
 
 
42
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
43
+
44
+ outputs = model.generate(
45
+ **inputs,
46
+ max_new_tokens=256 if mode == "detailed" else 128,
47
+ do_sample=True,
48
+ temperature=0.7,
49
+ top_p=0.95,
50
+ )
51
 
52
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
53
 
 
63
  except Exception as e:
64
  return f"An error occurred: {str(e)}"
65
 
66
+ # Create Gradio interface with queuing enabled
67
  with gr.Blocks(title="Live Coding HR Assistant") as demo:
68
  gr.Markdown("# 💻 Live Coding HR Assistant")
69
  gr.Markdown("Get hints, feedback, and follow-up questions for your coding tasks!")
 
102
  submit_btn.click(
103
  fn=generate_response,
104
  inputs=[task_description, code_snippet, request_type, mode],
105
+ outputs=output,
106
+ api_name="predict",
107
+ queue=True, # Enable queueing
108
+ max_batch_size=1
109
  )
110
 
111
+ demo.queue(max_size=10).launch(
112
+ server_name="0.0.0.0",
113
+ server_port=7860,
114
+ share=True,
115
+ enable_queue=True
116
+ )