Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
|
| 6 |
+
# Inicializa o pipeline do Hugging Face
|
| 7 |
+
llm = pipeline("text-generation", model="gpt-2")
|
| 8 |
+
|
| 9 |
+
# Define os templates de prompt
|
| 10 |
+
prompt_template_br = (
|
| 11 |
+
"Você é um analista de teste, responsável pela criação de testes unitários, com base na história de usuário {us} "
|
| 12 |
+
"e nos critérios de aceites {ca} baseados no gherking, crie os testes unitários para a linguagem de programação {lp} "
|
| 13 |
+
"baseados no framework {fw} "
|
| 14 |
+
"e explique como usar o código"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
prompt_template = (
|
| 18 |
+
"You are a test analyst, responsible for creating unit tests based on the user story {us} "
|
| 19 |
+
"and the acceptance criteria {ca} based on Gherkin. Create the unit tests for the programming language {lp} "
|
| 20 |
+
"based on the {fw} framework and explain how to use the code."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Interface do Streamlit
|
| 24 |
+
st.title("AutoDevSuite : BDD-based Test Generator")
|
| 25 |
+
us = st.text_area("Enter US:")
|
| 26 |
+
ca = st.text_area("Enter your Gherkin-based acceptance criteria:")
|
| 27 |
+
lp = st.text_input("Enter the programming language:")
|
| 28 |
+
fw = st.text_input("Enter the framework:")
|
| 29 |
+
|
| 30 |
+
prompt = PromptTemplate(
|
| 31 |
+
input_variables=["us", "ca", "lp", "fw"],
|
| 32 |
+
template=prompt_template
|
| 33 |
+
)
|
| 34 |
+
chain_1 = LLMChain(llm=llm, prompt=prompt)
|
| 35 |
+
|
| 36 |
+
if st.button("Generate Unit Tests"):
|
| 37 |
+
# Gera o resultado usando os valores de entrada
|
| 38 |
+
inputs = {"us": us, "ca": ca, "lp": lp, "fw": fw}
|
| 39 |
+
formatted_prompt = prompt.format(inputs)
|
| 40 |
+
|
| 41 |
+
# Utiliza o modelo da Hugging Face para gerar o texto
|
| 42 |
+
result = llm(formatted_prompt, max_length=512, num_return_sequences=1)[0]['generated_text']
|
| 43 |
+
|
| 44 |
+
# Exibe o resultado
|
| 45 |
+
st.write("Results:")
|
| 46 |
+
st.write(result)
|