Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
code_gen_model = T5ForConditionalGeneration.from_pretrained(model_path)
|
| 7 |
tokenizer = T5Tokenizer.from_pretrained(model_path)
|
| 8 |
|
| 9 |
-
# UI
|
| 10 |
st.title("Code Generation Interface")
|
| 11 |
|
| 12 |
# Input prompt for code generation
|
|
@@ -14,9 +20,15 @@ prompt = st.text_input("Enter your code generation prompt:", "Example prompt")
|
|
| 14 |
|
| 15 |
# Button to generate code
|
| 16 |
if st.button("Generate Code"):
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Display the generated code
|
| 21 |
st.write("Generated Code:")
|
| 22 |
st.code(generated_code)
|
|
|
|
| 1 |
+
import os
|
| 2 |
import streamlit as st
|
| 3 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Define the model path and check if it exists
|
| 7 |
+
model_path = "Cegil/code_generation" # Update to your model's actual path
|
| 8 |
+
if not os.path.exists(model_path):
|
| 9 |
+
raise FileNotFoundError(f"Model path '{model_path}' does not exist.")
|
| 10 |
+
|
| 11 |
+
# Load the model and tokenizer
|
| 12 |
code_gen_model = T5ForConditionalGeneration.from_pretrained(model_path)
|
| 13 |
tokenizer = T5Tokenizer.from_pretrained(model_path)
|
| 14 |
|
| 15 |
+
# Streamlit UI
|
| 16 |
st.title("Code Generation Interface")
|
| 17 |
|
| 18 |
# Input prompt for code generation
|
|
|
|
| 20 |
|
| 21 |
# Button to generate code
|
| 22 |
if st.button("Generate Code"):
|
| 23 |
+
# Tokenize the input prompt
|
| 24 |
+
inputs = tokenizer(prompt, return_tensors="pt") # Ensure input is properly tokenized
|
| 25 |
+
|
| 26 |
+
# Generate code using the code generation model
|
| 27 |
+
output = code_gen_model.generate(inputs['input_ids'])
|
| 28 |
+
|
| 29 |
+
# Decode the output to get the generated code
|
| 30 |
+
generated_code = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 31 |
|
| 32 |
+
# Display the generated code in a formatted way
|
| 33 |
st.write("Generated Code:")
|
| 34 |
st.code(generated_code)
|