Spaces:
Running
Running
acecalisto3
commited on
Commit
•
86363d9
1
Parent(s):
6f2142c
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import subprocess
|
|
4 |
import random
|
5 |
import string
|
6 |
from huggingface_hub import cached_download, hf_hub_url
|
7 |
-
from transformers import pipeline
|
8 |
import black
|
9 |
import pylint
|
10 |
|
@@ -110,6 +110,44 @@ def summarize_text(text):
|
|
110 |
summary = summarizer(text, max_length=100, min_length=30)[0]['summary_text']
|
111 |
return summary
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# Streamlit App
|
114 |
st.title("CodeCraft: Your AI-Powered Development Toolkit")
|
115 |
|
@@ -147,4 +185,11 @@ st.header("AI-Powered Tools")
|
|
147 |
text_to_summarize = st.text_area("Enter text to summarize:")
|
148 |
if st.button("Summarize"):
|
149 |
summary = summarize_text(text_to_summarize)
|
150 |
-
st.write(f"Summary: {summary}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import random
|
5 |
import string
|
6 |
from huggingface_hub import cached_download, hf_hub_url
|
7 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
8 |
import black
|
9 |
import pylint
|
10 |
|
|
|
110 |
summary = summarizer(text, max_length=100, min_length=30)[0]['summary_text']
|
111 |
return summary
|
112 |
|
113 |
+
# 6. Code Generation
|
114 |
+
def generate_code(idea):
|
115 |
+
"""Generates code based on a given idea using the bigscience/T0_3B model.
|
116 |
+
|
117 |
+
Args:
|
118 |
+
idea: The idea for the code to be generated.
|
119 |
+
|
120 |
+
Returns:
|
121 |
+
The generated code as a string.
|
122 |
+
"""
|
123 |
+
|
124 |
+
# Load the code generation model
|
125 |
+
model_name = 'bigscience/T0_3B' # Choose your model
|
126 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
127 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
128 |
+
|
129 |
+
# Generate the code
|
130 |
+
input_text = f"""
|
131 |
+
# Idea: {idea}
|
132 |
+
# Code:
|
133 |
+
"""
|
134 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
135 |
+
output_sequences = model.generate(
|
136 |
+
input_ids=input_ids,
|
137 |
+
max_length=1024,
|
138 |
+
num_return_sequences=1,
|
139 |
+
no_repeat_ngram_size=2,
|
140 |
+
early_stopping=True,
|
141 |
+
temperature=0.7, # Adjust temperature for creativity
|
142 |
+
top_k=50, # Adjust top_k for diversity
|
143 |
+
)
|
144 |
+
generated_code = tokenizer.decode(output_sequences[0], skip_special_tokens=True)
|
145 |
+
|
146 |
+
# Remove the prompt and formatting
|
147 |
+
generated_code = generated_code.split("\n# Code:")[1].strip()
|
148 |
+
|
149 |
+
return generated_code
|
150 |
+
|
151 |
# Streamlit App
|
152 |
st.title("CodeCraft: Your AI-Powered Development Toolkit")
|
153 |
|
|
|
185 |
text_to_summarize = st.text_area("Enter text to summarize:")
|
186 |
if st.button("Summarize"):
|
187 |
summary = summarize_text(text_to_summarize)
|
188 |
+
st.write(f"Summary: {summary}")
|
189 |
+
|
190 |
+
# Code Generation
|
191 |
+
st.header("Code Generation")
|
192 |
+
code_idea = st.text_input("Enter your code idea:")
|
193 |
+
if st.button("Generate Code"):
|
194 |
+
generated_code = generate_code(code_idea)
|
195 |
+
st.code(generated_code, language="python")
|