Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Initial data
|
5 |
+
data = {
|
6 |
+
'Name': ['Alice', 'Bob', 'Charlie'],
|
7 |
+
'Age': [25, 30, 35],
|
8 |
+
'City': ['New York', 'Los Angeles', 'Chicago'],
|
9 |
+
'Feedback': [None, None, None]
|
10 |
+
}
|
11 |
+
df = pd.DataFrame(data)
|
12 |
+
|
13 |
+
# Function to add feedback
|
14 |
+
def add_feedback(name, feedback):
|
15 |
+
global df
|
16 |
+
df.loc[df['Name'] == name, 'Feedback'] = feedback
|
17 |
+
return df
|
18 |
+
|
19 |
+
# Function to get a response from GPT (placeholder for actual GPT call)
|
20 |
+
def get_gpt_response(question):
|
21 |
+
# Convert DataFrame to CSV string
|
22 |
+
csv_data = df.to_csv(index=False)
|
23 |
+
# Create context with feedback
|
24 |
+
context = f"""
|
25 |
+
Here is the data of people including their names, ages, cities they live in, and feedback:
|
26 |
+
|
27 |
+
{csv_data}
|
28 |
+
|
29 |
+
Question: {question}
|
30 |
+
"""
|
31 |
+
# Placeholder for GPT call
|
32 |
+
response = "Charlie, 35 years old, from Chicago is the oldest person."
|
33 |
+
return response
|
34 |
+
|
35 |
+
def ask_question(question):
|
36 |
+
response = get_gpt_response(question)
|
37 |
+
return response
|
38 |
+
|
39 |
+
def submit_feedback(name, feedback):
|
40 |
+
updated_df = add_feedback(name, feedback)
|
41 |
+
return updated_df
|
42 |
+
|
43 |
+
with gr.Blocks() as demo:
|
44 |
+
gr.Markdown("# Data Inquiry and Feedback System")
|
45 |
+
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
question_input = gr.Textbox(label="Ask a Question")
|
49 |
+
response_output = gr.Textbox(label="GPT Response", interactive=False)
|
50 |
+
ask_button = gr.Button("Ask")
|
51 |
+
|
52 |
+
with gr.Column():
|
53 |
+
name_input = gr.Textbox(label="Name for Feedback")
|
54 |
+
feedback_input = gr.Textbox(label="Feedback")
|
55 |
+
submit_button = gr.Button("Submit Feedback")
|
56 |
+
feedback_df = gr.Dataframe(label="Updated DataFrame", interactive=False)
|
57 |
+
|
58 |
+
ask_button.click(fn=ask_question, inputs=question_input, outputs=response_output)
|
59 |
+
submit_button.click(fn=submit_feedback, inputs=[name_input, feedback_input], outputs=feedback_df)
|
60 |
+
|
61 |
+
demo.launch()
|