Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,32 +2,32 @@ import pandas as pd
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
|
5 |
-
model_name = "
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
-
#
|
10 |
data = {
|
11 |
-
'
|
12 |
-
'
|
13 |
-
'
|
14 |
'Feedback': [None, None, None]
|
15 |
}
|
16 |
df = pd.DataFrame(data)
|
17 |
|
18 |
-
#
|
19 |
-
def add_feedback(
|
20 |
global df
|
21 |
-
df.loc[df['
|
22 |
return df
|
23 |
|
24 |
-
#
|
25 |
def get_gpt_response(query):
|
26 |
-
#
|
27 |
csv_data = df.to_csv(index=False)
|
28 |
-
#
|
29 |
context = f"""
|
30 |
-
|
31 |
|
32 |
{csv_data}
|
33 |
|
@@ -36,28 +36,28 @@ def get_gpt_response(query):
|
|
36 |
output = model.generate(input_ids, max_new_tokens=100)
|
37 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
38 |
|
39 |
-
def ask_question(
|
40 |
-
|
41 |
-
return
|
42 |
|
43 |
-
def submit_feedback(
|
44 |
-
updated_df = add_feedback(
|
45 |
return updated_df
|
46 |
|
47 |
with gr.Blocks() as demo:
|
48 |
-
gr.Markdown("#
|
49 |
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
-
question_input = gr.Textbox(label="
|
53 |
-
response_output = gr.Textbox(label="GPT
|
54 |
-
ask_button = gr.Button("
|
55 |
|
56 |
with gr.Column():
|
57 |
-
name_input = gr.Textbox(label="
|
58 |
feedback_input = gr.Textbox(label="Feedback")
|
59 |
-
submit_button = gr.Button("
|
60 |
-
feedback_df = gr.Dataframe(label="
|
61 |
|
62 |
ask_button.click(fn=ask_question, inputs=question_input, outputs=response_output)
|
63 |
submit_button.click(fn=submit_feedback, inputs=[name_input, feedback_input], outputs=feedback_df)
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
|
5 |
+
model_name = "meta-llama/Llama-2-7b"
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
+
# Dados iniciais
|
10 |
data = {
|
11 |
+
'Nome': ['Alice', 'Bob', 'Charlie'],
|
12 |
+
'Idade': [25, 30, 35],
|
13 |
+
'Cidade': ['Nova York', 'Los Angeles', 'Chicago'],
|
14 |
'Feedback': [None, None, None]
|
15 |
}
|
16 |
df = pd.DataFrame(data)
|
17 |
|
18 |
+
# Função para adicionar feedback
|
19 |
+
def add_feedback(nome, feedback):
|
20 |
global df
|
21 |
+
df.loc[df['Nome'] == nome, 'Feedback'] = feedback
|
22 |
return df
|
23 |
|
24 |
+
# Função para obter uma resposta do GPT (substituição para chamada real ao GPT)
|
25 |
def get_gpt_response(query):
|
26 |
+
# Converte o DataFrame para string CSV
|
27 |
csv_data = df.to_csv(index=False)
|
28 |
+
# Cria contexto com feedback
|
29 |
context = f"""
|
30 |
+
Aqui estão os dados das pessoas incluindo seus nomes, idades, cidades onde moram e feedback:
|
31 |
|
32 |
{csv_data}
|
33 |
|
|
|
36 |
output = model.generate(input_ids, max_new_tokens=100)
|
37 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
38 |
|
39 |
+
def ask_question(pergunta):
|
40 |
+
resposta = get_gpt_response(pergunta)
|
41 |
+
return resposta
|
42 |
|
43 |
+
def submit_feedback(nome, feedback):
|
44 |
+
updated_df = add_feedback(nome, feedback)
|
45 |
return updated_df
|
46 |
|
47 |
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("# Sistema de Consulta e Feedback de Dados")
|
49 |
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
+
question_input = gr.Textbox(label="Faça uma Pergunta")
|
53 |
+
response_output = gr.Textbox(label="Resposta do GPT", interactive=False)
|
54 |
+
ask_button = gr.Button("Perguntar")
|
55 |
|
56 |
with gr.Column():
|
57 |
+
name_input = gr.Textbox(label="Nome para Feedback")
|
58 |
feedback_input = gr.Textbox(label="Feedback")
|
59 |
+
submit_button = gr.Button("Enviar Feedback")
|
60 |
+
feedback_df = gr.Dataframe(label="DataFrame Atualizado", interactive=False)
|
61 |
|
62 |
ask_button.click(fn=ask_question, inputs=question_input, outputs=response_output)
|
63 |
submit_button.click(fn=submit_feedback, inputs=[name_input, feedback_input], outputs=feedback_df)
|