Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,12 +17,38 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 17 |
|
| 18 |
# Streamlit UI
|
| 19 |
st.title("Gemma-2B-IT Text Generator")
|
| 20 |
-
st.write("Enter
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
max_length = st.slider("Max Length", min_value=50, max_value=500, value=400)
|
| 27 |
temperature = st.slider("Temperature", min_value=0.1, max_value=1.5, value=0.7)
|
| 28 |
top_p = st.slider("Top-p (nucleus sampling)", min_value=0.0, max_value=1.0, value=0.9)
|
|
@@ -31,9 +57,9 @@ do_sample = st.checkbox("Enable Sampling", value=True)
|
|
| 31 |
|
| 32 |
# Generate text when the button is pressed
|
| 33 |
if st.button("Generate"):
|
| 34 |
-
input_ids = tokenizer(
|
| 35 |
|
| 36 |
-
#
|
| 37 |
outputs = model.generate(
|
| 38 |
**input_ids,
|
| 39 |
max_length=max_length,
|
|
|
|
| 17 |
|
| 18 |
# Streamlit UI
|
| 19 |
st.title("Gemma-2B-IT Text Generator")
|
| 20 |
+
st.write("Enter the text and generate a structured prompt.")
|
| 21 |
|
| 22 |
+
# User inputs the text
|
| 23 |
+
text = st.text_area("Input your text",
|
| 24 |
+
"“El sistema CRISPR-Cas9 permite una edición precisa del genoma mediante la creación de rupturas de doble cadena en ubicaciones específicas del ADN, lo que facilita modificaciones genéticas específicas.”")
|
| 25 |
|
| 26 |
+
# Create a formatted prompt using the provided text
|
| 27 |
+
prompt = f"""
|
| 28 |
+
Realiza las siguientes acciones:
|
| 29 |
+
1 - Tradúceme el texto delimitado por las comillas triples a inglés, árabe y francés.
|
| 30 |
+
2 - Identifícame el tema principal del texto delimitado por las comillas triples.
|
| 31 |
+
3 - Obtén el tono en el que está escrito el texto delimitado por las comillas triples.
|
| 32 |
+
4 - Devuelve el resultado de cada paso en un JSON con el siguiente formato:
|
| 33 |
+
{{
|
| 34 |
+
"Traduccion": {{
|
| 35 |
+
"Ingles": "",
|
| 36 |
+
"Arabe": "",
|
| 37 |
+
"Frances": ""
|
| 38 |
+
}},
|
| 39 |
+
"TemaPrincipal": "",
|
| 40 |
+
"Tono": ""
|
| 41 |
+
}}
|
| 42 |
+
|
| 43 |
+
Text:
|
| 44 |
+
```{text}```
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
# Show the formatted prompt for user to see
|
| 48 |
+
st.write("Your formatted prompt:")
|
| 49 |
+
st.text_area("Formatted Prompt", prompt, height=300)
|
| 50 |
+
|
| 51 |
+
# Sliders for generation parameters
|
| 52 |
max_length = st.slider("Max Length", min_value=50, max_value=500, value=400)
|
| 53 |
temperature = st.slider("Temperature", min_value=0.1, max_value=1.5, value=0.7)
|
| 54 |
top_p = st.slider("Top-p (nucleus sampling)", min_value=0.0, max_value=1.0, value=0.9)
|
|
|
|
| 57 |
|
| 58 |
# Generate text when the button is pressed
|
| 59 |
if st.button("Generate"):
|
| 60 |
+
input_ids = tokenizer(prompt, return_tensors="pt")
|
| 61 |
|
| 62 |
+
# Generate text with specified parameters
|
| 63 |
outputs = model.generate(
|
| 64 |
**input_ids,
|
| 65 |
max_length=max_length,
|