Cegil commited on
Commit
e23f935
1 Parent(s): f7e25a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,12 +1,18 @@
 
1
  import streamlit as st
2
- from transformers import T5ForConditionalGeneration, T5Tokenizer # Replace with the library used for your code generation model
3
- import sentencepiece as spm
4
- # Load your code generation model
5
- model_path = "Cegil/code_generation" # e.g., a model checkpoint or saved weights
 
 
 
 
 
6
  code_gen_model = T5ForConditionalGeneration.from_pretrained(model_path)
7
  tokenizer = T5Tokenizer.from_pretrained(model_path)
8
 
9
- # UI for Code Generation
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
- # Use the code generation model to generate code based on the prompt
18
- generated_code = code_gen_model.generate(prompt) # Adapt this to your model's method
 
 
 
 
 
 
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)