AEUPH commited on
Commit
681fe2a
·
verified ·
1 Parent(s): 85d50eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -86,13 +86,42 @@ def process_menu_selection(data):
86
  # Package the response as JSON
87
  response = json.dumps({"nextMenu": next_menu, "currentMenu": new_current_menu})
88
  return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- # Create a Gradio interface for the app
91
- iface = gr.Interface(fn=process_menu_selection,
92
  inputs="text",
93
  outputs="text",
94
- description="Process menu selections and return the next set of options.")
95
 
96
- # Example usage with Gradio
97
- iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
98
  iface.launch()
 
86
  # Package the response as JSON
87
  response = json.dumps({"nextMenu": next_menu, "currentMenu": new_current_menu})
88
  return response
89
+ def process_selection(data):
90
+ print("Received data:", data) # Debugging print
91
+ selection_info = json.loads(data)
92
+ user_choice = selection_info.get("user_choice", "default")
93
+ current_menu = selection_info.get("current_menu", "main")
94
+
95
+ # Simplified logic for debugging
96
+ if user_choice == "Creativity":
97
+ next_menu = ["Painting", "Writing", "Music"]
98
+ else:
99
+ next_menu = ["Option A", "Option B"]
100
+
101
+ response = json.dumps({"nextMenu": next_menu, "currentMenu": user_choice})
102
+ return response
103
+
104
+ def universal_processor(input_text):
105
+ if input_text.startswith("menu:"):
106
+ # Extract and process menu selection
107
+ return process_menu_selection(input_text[5:])
108
+ elif input_text.startswith("chat:"):
109
+ # Handle chatbot interaction
110
+ return chatbot_api(input_text[5:])
111
+ else:
112
+ return "Unrecognized command"
113
+
114
+ def process_menu_selection(selection):
115
+ # Your menu processing logic here
116
+ return f"Menu selection processed: {selection}"
117
+
118
+ def chatbot_api(message):
119
+ # Your chatbot logic here
120
+ return f"Chatbot response to: {message}"
121
 
122
+ iface = gr.Interface(fn=universal_processor,
 
123
  inputs="text",
124
  outputs="text",
125
+ description="Enter 'menu:' followed by your selection or 'chat:' followed by your message.")
126
 
 
 
127
  iface.launch()