Spaces:
Runtime error
Runtime error
mrolando commited on
Commit 路
22d7a90
1
Parent(s): 5e589fb
first commit
Browse files- .gitignore +2 -0
- Iso_Logotipo_Ceibal.png +0 -0
- app.py +59 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
env
|
Iso_Logotipo_Ceibal.png
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline, Conversation
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load environment variables from the .env file de forma local
|
| 7 |
+
load_dotenv()
|
| 8 |
+
import base64
|
| 9 |
+
|
| 10 |
+
with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
|
| 11 |
+
encoded_image = base64.b64encode(image_file.read()).decode()
|
| 12 |
+
import os
|
| 13 |
+
import openai
|
| 14 |
+
|
| 15 |
+
openai.api_key = os.environ['OPENAI_API_KEY']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def add_new_message(pregunta,respuesta):
|
| 19 |
+
new_chat = []
|
| 20 |
+
new_chat.append({"role": "system", "content": 'Sos mentor de un curso de Pensamiento Computacional en una plataforma online. Los estudiantes son docentes hombres y mujeres de educaci贸n secundaria en Uruguay. Te enviar茅 preguntas que se hacen en el foro del curso y una respuesta para calificar. Deber谩s indicarme una valoraci贸n de la respuesta y un puntaje en la escala del 1 al 5, siendo 1 el puntaje m铆nimo y 5 el m谩ximo. El formato de la salida deber谩 ser el siguiente (los valores son solamente a modo de ejemplo): "Puntaje: 3. Valoraci贸n: La respuesta est谩 bien y describe de forma correcta lo que se pregunta. Se podr铆a haber discutido un poco m谩s sobre el concepto de aprendizaje.'})
|
| 21 |
+
new_chat.append({"role": "user","content":'Pregunta: {} .Respuesta a calificar {}'.format(pregunta,respuesta)})
|
| 22 |
+
return new_chat
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def respond(pregunta, respuesta):
|
| 27 |
+
prompt = add_new_message(pregunta, respuesta)
|
| 28 |
+
response = openai.ChatCompletion.create(
|
| 29 |
+
model="gpt-3.5-turbo",
|
| 30 |
+
messages= prompt,
|
| 31 |
+
temperature=0.5,
|
| 32 |
+
max_tokens=120
|
| 33 |
+
).choices[0].message.content
|
| 34 |
+
return response
|
| 35 |
+
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
+
gr.Markdown("""
|
| 38 |
+
<center>
|
| 39 |
+
<h1>
|
| 40 |
+
Correcci贸n de tareas con ChatGPT
|
| 41 |
+
</h1>
|
| 42 |
+
<img src='data:image/jpg;base64,{}' width=200px>
|
| 43 |
+
<h3>
|
| 44 |
+
Con este espacio podr谩s hablar en formato conversaci贸n con ChatGTP!
|
| 45 |
+
</h3>
|
| 46 |
+
</center>
|
| 47 |
+
""".format(encoded_image))
|
| 48 |
+
with gr.Row():
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
msg = gr.Textbox(label="Pregunta")
|
| 52 |
+
msg2 = gr.Textbox(label="Respuesta")
|
| 53 |
+
btn = gr.Button("Enviar")
|
| 54 |
+
|
| 55 |
+
with gr.Column():
|
| 56 |
+
output = gr.Textbox(label="Respuesta de ChatGPT")
|
| 57 |
+
|
| 58 |
+
btn.click(respond, inputs=[msg, msg2], outputs=output)
|
| 59 |
+
demo.launch()
|