Spaces:
Runtime error
Runtime error
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() | |