File size: 1,904 Bytes
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
import pandas as pd
import gradio as gr

# Initial data
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago'],
    'Feedback': [None, None, None]
}
df = pd.DataFrame(data)

# Function to add feedback
def add_feedback(name, feedback):
    global df
    df.loc[df['Name'] == name, 'Feedback'] = feedback
    return df

# Function to get a response from GPT (placeholder for actual GPT call)
def get_gpt_response(question):
    # Convert DataFrame to CSV string
    csv_data = df.to_csv(index=False)
    # Create context with feedback
    context = f"""
    Here is the data of people including their names, ages, cities they live in, and feedback:

    {csv_data}

    Question: {question}
    """
    # Placeholder for GPT call
    response = "Charlie, 35 years old, from Chicago is the oldest person."
    return response

def ask_question(question):
    response = get_gpt_response(question)
    return response

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

with gr.Blocks() as demo:
    gr.Markdown("# Data Inquiry and Feedback System")

    with gr.Row():
        with gr.Column():
            question_input = gr.Textbox(label="Ask a Question")
            response_output = gr.Textbox(label="GPT Response", interactive=False)
            ask_button = gr.Button("Ask")

        with gr.Column():
            name_input = gr.Textbox(label="Name for Feedback")
            feedback_input = gr.Textbox(label="Feedback")
            submit_button = gr.Button("Submit Feedback")
            feedback_df = gr.Dataframe(label="Updated DataFrame", 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()