Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -140,7 +140,7 @@ sp_pseudo = spm.SentencePieceProcessor(model_file="pseudo.model") # For decodin
|
|
140 |
sp_code = spm.SentencePieceProcessor(model_file="code.model") # For encoding C++ (source)
|
141 |
|
142 |
# Load the full saved model (architecture + weights)
|
143 |
-
model_path = "transformer_cpp_to_pseudo.pth"
|
144 |
model = torch.load(model_path, map_location=device, weights_only=False)
|
145 |
model.eval()
|
146 |
model = model.to(device)
|
@@ -170,17 +170,26 @@ def respond(message, history, max_tokens):
|
|
170 |
for response in generate_pseudocode(message, max_tokens):
|
171 |
yield response
|
172 |
|
173 |
-
# Gradio
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
if __name__ == "__main__":
|
186 |
demo.launch()
|
|
|
140 |
sp_code = spm.SentencePieceProcessor(model_file="code.model") # For encoding C++ (source)
|
141 |
|
142 |
# Load the full saved model (architecture + weights)
|
143 |
+
model_path = "transformer_cpp_to_pseudo.pth"
|
144 |
model = torch.load(model_path, map_location=device, weights_only=False)
|
145 |
model.eval()
|
146 |
model = model.to(device)
|
|
|
170 |
for response in generate_pseudocode(message, max_tokens):
|
171 |
yield response
|
172 |
|
173 |
+
# Gradio UI setup with Blocks
|
174 |
+
with gr.Blocks(title="C++ to Pseudocode Transformer") as demo:
|
175 |
+
gr.Markdown("## C++ to Pseudocode Converter")
|
176 |
+
gr.Markdown("Enter C++ code below and press Submit to generate pseudocode.")
|
177 |
+
cpp_input = gr.Textbox(
|
178 |
+
label="C++ Code",
|
179 |
+
placeholder="e.g., 'int x = 5; for(int i=0; i<x; i++) cout << i;'",
|
180 |
+
lines=5
|
181 |
+
)
|
182 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
183 |
+
pseudocode_output = gr.Textbox(
|
184 |
+
label="Generated Pseudocode",
|
185 |
+
lines=5
|
186 |
+
)
|
187 |
+
|
188 |
+
submit_btn.click(
|
189 |
+
fn=respond,
|
190 |
+
inputs=[cpp_input, gr.State(value=[]), gr.Slider(minimum=10, maximum=1000, value=50, step=1, visible=False)],
|
191 |
+
outputs=pseudocode_output
|
192 |
+
)
|
193 |
|
194 |
if __name__ == "__main__":
|
195 |
demo.launch()
|