File size: 2,353 Bytes
723fe48
 
b531f3a
76302e9
82871f4
b531f3a
 
723fe48
48eef38
723fe48
48eef38
 
 
723fe48
 
 
 
48eef38
 
723fe48
48eef38
723fe48
 
48eef38
82871f4
48eef38
723fe48
48eef38
723fe48
48eef38
723fe48
 
82871f4
723fe48
b531f3a
 
 
c815f34
b531f3a
 
ba48fb7
723fe48
48eef38
 
 
723fe48
48eef38
 
723fe48
 
 
48eef38
723fe48
 
 
48eef38
 
 
723fe48
 
48eef38
723fe48
48eef38
 
723fe48
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pandas as pd
import gradio as gr
from transformers import BertTokenizer, BertForSequenceClassification
import torch

tokenizer = BertTokenizer.from_pretrained('juridics/bertimbaulaw-base-portuguese-sts-scale')
model = BertForSequenceClassification.from_pretrained('juridics/bertimbaulaw-base-portuguese-sts-scale')

# Dados iniciais
data = {
    'Nome': ['Alice', 'Bob', 'Charlie'],
    'Idade': [25, 30, 35],
    'Cidade': ['Nova York', 'Los Angeles', 'Chicago'],
    'Feedback': [None, None, None]
}
df = pd.DataFrame(data)

# Função para adicionar feedback
def add_feedback(nome, feedback):
    global df
    df.loc[df['Nome'] == nome, 'Feedback'] = feedback
    return df

# Função para obter uma resposta do GPT (substituição para chamada real ao GPT)
def get_gpt_response(query):
    # Converte o DataFrame para string CSV
    csv_data = df.to_csv(index=False)
    # Cria contexto com feedback
    context = f"""
    Aqui estão os dados das pessoas incluindo seus nomes, idades, cidades onde moram e feedback:

    {csv_data}
    
    """
    inputs = tokenizer(query, return_tensors="pt", padding=True, truncation=True)
    outputs = model(**inputs)
    prediction = torch.argmax(outputs.logits, dim=1)
    labels = data.columns
    predicted_label = labels[prediction]
    return predicted_label


def ask_question(pergunta):
    resposta = get_gpt_response(pergunta)
    return resposta

def submit_feedback(nome, feedback):
    updated_df = add_feedback(nome, feedback)
    return updated_df

with gr.Blocks() as demo:
    gr.Markdown("# Sistema de Consulta e Feedback de Dados")

    with gr.Row():
        with gr.Column():
            question_input = gr.Textbox(label="Faça uma Pergunta")
            response_output = gr.Textbox(label="Resposta do GPT", interactive=False)
            ask_button = gr.Button("Perguntar")

        with gr.Column():
            name_input = gr.Textbox(label="Nome para Feedback")
            feedback_input = gr.Textbox(label="Feedback")
            submit_button = gr.Button("Enviar Feedback")
            feedback_df = gr.Dataframe(label="DataFrame Atualizado", interactive=False)
    
    ask_button.click(fn=ask_question, inputs=question_input, outputs=response_output)
    submit_button.click(fn=submit_feedback, inputs=[name_input, feedback_input], outputs=feedback_df)

demo.launch()