elaineaishophouse commited on
Commit
11926bf
·
verified ·
1 Parent(s): 101ccba

Upload PanelInterface.py

Browse files
Files changed (1) hide show
  1. PanelInterface.py +84 -0
PanelInterface.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import logging
4
+
5
+ def chatbot_interface(message, history=None):
6
+ if history is None:
7
+ history = []
8
+ response = f"You asked: {message}"
9
+ history.append({"role": "user", "content": message})
10
+ history.append({"role": "assistant", "content": response})
11
+ return history, "", history
12
+
13
+ def build_interface():
14
+ logging.info("Building Gradio interface...")
15
+
16
+ panelists = [
17
+ {"ID": "P1", "Name": "Sourav", "Description": "Student from Kolkata", "Bio": "Sourav is a 25-year-old sociology student from Kolkata."},
18
+ {"ID": "P2", "Name": "Anjali", "Description": "College student from Chennai", "Bio": "Anjali is a 17-year-old girl from Chennai, aspiring to be a psychologist."},
19
+ {"ID": "P3", "Name": "Ravi", "Description": "Teen from Hyderabad", "Bio": "Ravi is a high schooler passionate about cricket and coding."},
20
+ {"ID": "P4", "Name": "Divya", "Description": "Engineering student from Trichy", "Bio": "Divya is 21, studying electronics in Trichy, with interests in AI and robotics."}
21
+ ]
22
+
23
+ panel_html = ""
24
+ bios_dict = {}
25
+
26
+ for p in panelists:
27
+ panel_html += f'<p><a href="#" onclick="showModal(event, \"{p["ID"]}\")"><b>{p["Name"]}</b></a> – {p["Description"]}</p>'
28
+ bios_dict[p["ID"]] = p["Bio"]
29
+
30
+ bios_js_object = str(bios_dict).replace("'", "\"")
31
+
32
+ with gr.Blocks(css="assets/custom.css") as demo:
33
+ with gr.Row(elem_classes="logo-row"):
34
+ gr.Image("predata-logo.png", height=200, show_label=False, elem_id="logo")
35
+
36
+ with gr.Row(elem_classes="welcome-section"):
37
+ gr.Markdown("""
38
+ # Welcome to PreData.AI's Market Research Panel [Demo]
39
+ ## Introducing our AI-powered panel:
40
+ - Ask a question by typing into the box below.
41
+ - You can address a question to a **specific panellist** or the entire group.
42
+ """)
43
+
44
+ with gr.Row():
45
+ with gr.Column(scale=1, elem_classes="bio-section"):
46
+ gr.HTML(f"""
47
+ <div style='text-align: left;'>
48
+ <h2>Our Panellists</h2>
49
+ {panel_html}
50
+ </div>
51
+ <div id='bioModal' style='display:none;position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);background-color:white;border:1px solid #ccc;box-shadow:0px 4px 6px rgba(0,0,0,0.2);width:400px;max-height:300px;padding:20px;text-align:left;z-index:1000;overflow-y:auto;'>
52
+ <p id='bioContent'></p>
53
+ <button onclick='closeModal()' style='margin-top:10px;padding:5px 10px;background-color:#007bff;color:white;border:none;border-radius:5px;cursor:pointer;'>Close</button>
54
+ </div>
55
+ <div id='modalBackdrop' style='display:none;position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.5);z-index:999;' onclick='closeModal()'></div>
56
+ <script>
57
+ const bios = {bios_js_object};
58
+ function showModal(event, name) {{
59
+ event.preventDefault();
60
+ document.getElementById('bioContent').innerText = bios[name] || 'Bio not found.';
61
+ document.getElementById('bioModal').style.display = 'block';
62
+ document.getElementById('modalBackdrop').style.display = 'block';
63
+ }}
64
+ function closeModal() {{
65
+ document.getElementById('bioModal').style.display = 'none';
66
+ document.getElementById('modalBackdrop').style.display = 'none';
67
+ }}
68
+ </script>
69
+ """)
70
+
71
+ with gr.Column(scale=3):
72
+ chatbot = gr.Chatbot(label="Panel Discussion", height=400, type="messages")
73
+ msg = gr.Textbox(placeholder="Ask your question to the panel here...")
74
+ history = gr.State([])
75
+ msg.submit(chatbot_interface, [msg, history], [chatbot, msg, history])
76
+
77
+ with gr.Row(elem_classes="footer-row"):
78
+ gr.Markdown("""
79
+ <div style="text-align:center;margin-top:20px;font-size:14px;">
80
+ © 2025 PreData.AI - All rights reserved.
81
+ </div>
82
+ """)
83
+
84
+ return demo