c
File size: 1,569 Bytes
6e0e241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
gradio as gr
from hugchat import hugchat
from hugchat.login import Login
import getpass  # Aseg煤rate de importar esta biblioteca para obtener la contrase帽a (en caso no hayas ejecutado las primeras celdas)

# Log in to huggingface and grant authorization to huggingchat
email = input("Ingrese su correo electr贸nico: ")
passwd = getpass.getpass("Ingrese su contrase帽a: ")

sign = Login(email, passwd)
cookies = sign.login()

# Save cookies to the local directory
cookie_path_dir = "./cookies_snapshot"
sign.saveCookiesToDir(cookie_path_dir)

# Create a ChatBot instance with cookies
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())

def generate_response(prompt):
    response = chatbot.chat(prompt)
    return response

def hugchat_app(prompt):
    response = generate_response(prompt)

    # Guarda la conversaci贸n en un archivo .txt
    with open("conversacion.txt", "a") as file:
        file.write("Usuario: " + prompt + "\n")
        file.write("ChatBot: " + response + "\n\n")

    return response

iface = gr.Interface(fn=hugchat_app, inputs="text", outputs="text", title="馃馃挰 ELISA I MODELO DE INTELIGENCIA ARTIFICIAL PROF: GERARDO", # Modificar como quieras
                     description="Esta aplicaci贸n es un chatbot impulsado por LLM creado utilizando HugChat. 馃挕",
                     article="Creado con 馃枻 por                        AREA DE INFORMATICA COLEGIO VILLA ELISA IED",
                     )
iface.launch(share=True, debug=True) # Si el problema se soluciona cambiar share a True para compartir URL (probar en unos d铆as)