Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,29 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
# Load model directly
|
| 4 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
|
| 6 |
-
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
# Encode the input text
|
| 11 |
-
text = "Eres un experto en lenguaje claro. Evalúa el texto siguiente y di si es muy claro, claro o poco claro. El texto es este: " + text
|
| 12 |
-
input_ids = tokenizer.encode(text, return_tensors="pt")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
min_length=100,
|
| 18 |
-
max_length=750,
|
| 19 |
-
eos_token_id=5,
|
| 20 |
-
pad_token_id=1,
|
| 21 |
-
top_k=10,
|
| 22 |
-
top_p=0.0,
|
| 23 |
-
no_repeat_ngram_size=5
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
-
demo
|
| 35 |
-
|
| 36 |
-
demo.launch(share=True)
|
|
|
|
| 1 |
+
import os
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
from groq import Groq
|
|
|
|
| 4 |
|
| 5 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
client = Groq(
|
| 8 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 9 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
def eval_text (text):
|
| 12 |
+
prompt = "Eres un experto en lenguaje claro. Evalúa la calidad del lenguaje de este texto:"
|
| 13 |
+
input = prompt + text
|
| 14 |
|
| 15 |
+
chat_completion = client.chat.completions.create(
|
| 16 |
+
messages=[
|
| 17 |
+
{
|
| 18 |
+
"role": "user",
|
| 19 |
+
"content": input,
|
| 20 |
+
}
|
| 21 |
+
],
|
| 22 |
+
model="mixtral-8x7b-32768",
|
| 23 |
+
)
|
| 24 |
|
| 25 |
+
return (chat_completion.choices[0].message.content)
|
| 26 |
|
| 27 |
+
demo = gr.Interface(fn=eval_text, inputs="text", outputs="text", title="EmpatIA")
|
| 28 |
|
| 29 |
+
demo.launch()
|
|
|
|
|
|