Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,7 @@ import gradio as gr
|
|
| 3 |
import torch
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
|
| 6 |
-
model_id = "lakshraina2/
|
| 7 |
-
|
| 8 |
-
# Securely grab the token you just saved in the Space settings
|
| 9 |
hf_token = os.environ.get("HF_TOKEN")
|
| 10 |
|
| 11 |
print("Loading model securely...")
|
|
@@ -18,28 +16,30 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 18 |
|
| 19 |
def solve(problem_text):
|
| 20 |
if not problem_text or len(problem_text) < 10:
|
| 21 |
-
return "// Error: Problem text too short
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 26 |
|
|
|
|
|
|
|
| 27 |
with torch.no_grad():
|
| 28 |
outputs = model.generate(
|
| 29 |
input_ids=inputs["input_ids"],
|
| 30 |
attention_mask=inputs["attention_mask"],
|
| 31 |
-
max_new_tokens=
|
| 32 |
-
|
| 33 |
-
temperature=0.1,
|
| 34 |
-
do_sample=True,
|
| 35 |
pad_token_id=tokenizer.eos_token_id
|
| 36 |
)
|
| 37 |
|
| 38 |
full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
demo = gr.Interface(fn=solve, inputs="text", outputs="text", api_name="predict")
|
| 45 |
demo.launch()
|
|
|
|
| 3 |
import torch
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
|
| 6 |
+
model_id = "lakshraina2/leetcode-coder-1.5B"
|
|
|
|
|
|
|
| 7 |
hf_token = os.environ.get("HF_TOKEN")
|
| 8 |
|
| 9 |
print("Loading model securely...")
|
|
|
|
| 16 |
|
| 17 |
def solve(problem_text):
|
| 18 |
if not problem_text or len(problem_text) < 10:
|
| 19 |
+
return "// Error: Problem text too short."
|
| 20 |
|
| 21 |
+
# Let's try a simpler, universal prompt format
|
| 22 |
+
prompt = f"Problem:\n{problem_text}\n\nPython code solution:\n"
|
| 23 |
|
| 24 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 25 |
|
| 26 |
+
print("Starting generation...") # This will show up in HF Logs
|
| 27 |
+
|
| 28 |
with torch.no_grad():
|
| 29 |
outputs = model.generate(
|
| 30 |
input_ids=inputs["input_ids"],
|
| 31 |
attention_mask=inputs["attention_mask"],
|
| 32 |
+
max_new_tokens=512,
|
| 33 |
+
do_sample=False, # Force deterministic greedy decoding
|
|
|
|
|
|
|
| 34 |
pad_token_id=tokenizer.eos_token_id
|
| 35 |
)
|
| 36 |
|
| 37 |
full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 38 |
|
| 39 |
+
print("RAW MODEL OUTPUT:\n", full_text) # Check HF logs to see exactly what it did
|
| 40 |
+
|
| 41 |
+
# TEMPORARY: Return the whole thing so you can see it in the GUI!
|
| 42 |
+
return full_text
|
| 43 |
|
| 44 |
demo = gr.Interface(fn=solve, inputs="text", outputs="text", api_name="predict")
|
| 45 |
demo.launch()
|