Spaces:
Running
Running
umm-maybe
commited on
Commit
·
c31c636
1
Parent(s):
b667694
Giving up on graph visualization
Browse files
app.py
CHANGED
@@ -1,38 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
-
from pyvis.network import Network
|
4 |
|
5 |
from transformers import pipeline
|
6 |
# Load the pipeline
|
7 |
tourModel = pipeline(model="manhan/GPT-Tour")
|
8 |
|
9 |
-
def vizTour(activityList):
|
10 |
-
net = Network(directed=True,notebook=False)
|
11 |
-
net.add_node(activityList[0])
|
12 |
-
lastActivity = activityList[0]
|
13 |
-
for activity in activityList[1:]:
|
14 |
-
if activity not in net.get_nodes():
|
15 |
-
net.add_node(activity)
|
16 |
-
net.add_edge(lastActivity, activity)
|
17 |
-
lastActivity = activity
|
18 |
-
net.save_graph('tour.html')
|
19 |
-
#tour_html = open('tour.html', 'r')
|
20 |
-
tour_html = gr.HTML("<iframe src=\"tour.html\"></iframe>")
|
21 |
-
return tour_html
|
22 |
-
|
23 |
def getTour(income,size,years,sex,edu,wrk):
|
24 |
# person = a dict with person-level and hh-level attributes:
|
25 |
person = {}
|
26 |
hh_income = int(income)
|
27 |
-
if hh_income<
|
28 |
-
_skip = 1 # nvm, bad data
|
29 |
-
elif hh_income<4: # $25,000
|
30 |
person['hh_inc'] = 'poor'
|
31 |
-
elif hh_income<
|
32 |
person['hh_inc'] = 'low'
|
33 |
-
elif hh_income<
|
34 |
person['hh_inc'] = 'medium'
|
35 |
-
elif hh_income<
|
36 |
person['hh_inc'] = 'high'
|
37 |
else: # over
|
38 |
person['hh_inc'] = 'affluent'
|
@@ -67,7 +50,6 @@ def getTour(income,size,years,sex,edu,wrk):
|
|
67 |
end_pos = generated.find(']')+1
|
68 |
activity_list_str = generated[start_pos:end_pos]
|
69 |
print(f"Extracted: '{activity_list_str}'")
|
70 |
-
# this check doesn't appear to work anyways
|
71 |
#if person['wrk']=='yes' and activity_list_str.find('Work')==-1:
|
72 |
# continue # try again
|
73 |
#if person['wrk']=='no' and activity_list_str.find('Work')>0:
|
@@ -84,8 +66,7 @@ def getTour(income,size,years,sex,edu,wrk):
|
|
84 |
print(e)
|
85 |
else:
|
86 |
print("Nothing extracted!")
|
87 |
-
|
88 |
-
return activity_list, tour_html
|
89 |
|
90 |
with gr.Interface(fn=getTour, inputs=[
|
91 |
gr.inputs.Textbox(label="Annual Household Income (in dollars)"),
|
@@ -94,5 +75,5 @@ with gr.Interface(fn=getTour, inputs=[
|
|
94 |
gr.inputs.Dropdown(["unknown", "male", "female"], label="Gender/sex"),
|
95 |
gr.inputs.Dropdown(["unknown", "grade school","highschool", "associates", "bachelors", "graduate"], label="Educational attainment level"),
|
96 |
gr.inputs.Dropdown(["unknown", "yes","no"], label="Worker status")],
|
97 |
-
outputs=["json"
|
98 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
|
|
3 |
|
4 |
from transformers import pipeline
|
5 |
# Load the pipeline
|
6 |
tourModel = pipeline(model="manhan/GPT-Tour")
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def getTour(income,size,years,sex,edu,wrk):
|
9 |
# person = a dict with person-level and hh-level attributes:
|
10 |
person = {}
|
11 |
hh_income = int(income)
|
12 |
+
if hh_income<25000: # $25,000
|
|
|
|
|
13 |
person['hh_inc'] = 'poor'
|
14 |
+
elif hh_income<50000: # $50,000
|
15 |
person['hh_inc'] = 'low'
|
16 |
+
elif hh_income<75000: # $75,000
|
17 |
person['hh_inc'] = 'medium'
|
18 |
+
elif hh_income<125000: # $125,000
|
19 |
person['hh_inc'] = 'high'
|
20 |
else: # over
|
21 |
person['hh_inc'] = 'affluent'
|
|
|
50 |
end_pos = generated.find(']')+1
|
51 |
activity_list_str = generated[start_pos:end_pos]
|
52 |
print(f"Extracted: '{activity_list_str}'")
|
|
|
53 |
#if person['wrk']=='yes' and activity_list_str.find('Work')==-1:
|
54 |
# continue # try again
|
55 |
#if person['wrk']=='no' and activity_list_str.find('Work')>0:
|
|
|
66 |
print(e)
|
67 |
else:
|
68 |
print("Nothing extracted!")
|
69 |
+
return activity_list
|
|
|
70 |
|
71 |
with gr.Interface(fn=getTour, inputs=[
|
72 |
gr.inputs.Textbox(label="Annual Household Income (in dollars)"),
|
|
|
75 |
gr.inputs.Dropdown(["unknown", "male", "female"], label="Gender/sex"),
|
76 |
gr.inputs.Dropdown(["unknown", "grade school","highschool", "associates", "bachelors", "graduate"], label="Educational attainment level"),
|
77 |
gr.inputs.Dropdown(["unknown", "yes","no"], label="Worker status")],
|
78 |
+
outputs=["json"], title="GPT-Tour", description="Generate a tour for a person", allow_flagging='never') as iface:
|
79 |
iface.launch()
|