Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -881,251 +881,251 @@ def transcribe_audio_from_media_url(media_url):
|
|
| 881 |
|
| 882 |
app = FastAPI()
|
| 883 |
|
| 884 |
-
@app.get("/state")
|
| 885 |
-
async def fetch_state():
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
@app.route("/whatsapp-webhook/", methods=["POST"])
|
| 889 |
-
async def whatsapp_webhook(request: Request):
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
|
| 935 |
|
| 936 |
-
# In[19]:
|
| 937 |
|
| 938 |
|
| 939 |
-
# Mock Gmail Login Function
|
| 940 |
-
def mock_login(email):
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
|
| 946 |
-
# User Onboarding Function
|
| 947 |
-
def onboarding_survey(role, industry, project_description):
|
| 948 |
-
|
| 949 |
-
|
| 950 |
|
| 951 |
-
# Mock Integration Functions
|
| 952 |
-
def integrate_todoist():
|
| 953 |
-
|
| 954 |
|
| 955 |
-
def integrate_evernote():
|
| 956 |
-
|
| 957 |
|
| 958 |
-
def integrate_calendar():
|
| 959 |
-
|
| 960 |
|
| 961 |
-
def load_svg_with_size(file_path, width="600px", height="400px"):
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
# In[20]:
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
# Gradio Demo
|
| 979 |
-
def create_gradio_interface(state=None):
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
|
| 1078 |
-
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
|
| 1082 |
-
|
| 1083 |
-
|
| 1084 |
-
|
| 1085 |
-
|
| 1086 |
-
|
| 1087 |
-
|
| 1088 |
-
|
| 1089 |
-
|
| 1090 |
-
|
| 1091 |
-
|
| 1092 |
-
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
|
| 1097 |
-
|
| 1098 |
-
|
| 1099 |
-
|
| 1100 |
-
|
| 1101 |
-
|
| 1102 |
-
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
| 1106 |
-
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
|
| 1130 |
|
| 1131 |
# In[21]:
|
|
|
|
| 881 |
|
| 882 |
app = FastAPI()
|
| 883 |
|
| 884 |
+
# @app.get("/state")
|
| 885 |
+
# async def fetch_state():
|
| 886 |
+
# return shared_state
|
| 887 |
+
|
| 888 |
+
# @app.route("/whatsapp-webhook/", methods=["POST"])
|
| 889 |
+
# async def whatsapp_webhook(request: Request):
|
| 890 |
+
# form_data = await request.form()
|
| 891 |
+
# # Log the form data to debug
|
| 892 |
+
# print("Received data:", form_data)
|
| 893 |
|
| 894 |
+
# # Extract message and user information
|
| 895 |
+
# incoming_msg = form_data.get("Body", "").strip()
|
| 896 |
+
# from_number = form_data.get("From", "")
|
| 897 |
+
# media_url = form_data.get("MediaUrl0", "")
|
| 898 |
+
# media_type = form_data.get("MediaContentType0", "")
|
| 899 |
+
|
| 900 |
+
# # Initialize response variables
|
| 901 |
+
# transcription = None
|
| 902 |
+
|
| 903 |
+
# if media_type.startswith("audio"):
|
| 904 |
+
# # If the media is an audio or video file, process it
|
| 905 |
+
# try:
|
| 906 |
+
# transcription = transcribe_audio_from_media_url(media_url)
|
| 907 |
+
# except Exception as e:
|
| 908 |
+
# return JSONResponse(
|
| 909 |
+
# {"error": f"Failed to process voice input: {str(e)}"}, status_code=500
|
| 910 |
+
# )
|
| 911 |
+
# # Determine message content: use transcription if available, otherwise use text message
|
| 912 |
+
# processed_input = transcription if transcription else incoming_msg
|
| 913 |
|
| 914 |
+
# logger.debug(f"Processed input: {processed_input}")
|
| 915 |
+
# try:
|
| 916 |
+
# # Generate response
|
| 917 |
+
# project_desc_table, _ = fetch_updated_state()
|
| 918 |
+
# if not project_desc_table.empty:
|
| 919 |
+
# task_analysis_txt, execution_status, execution_results = fn_process_task(project_desc_table, processed_input)
|
| 920 |
+
# update_gradio_state(task_analysis_txt, execution_status, execution_results)
|
| 921 |
|
| 922 |
+
# doc_url = 'Fail to generate doc'
|
| 923 |
+
# if 'doc_url' in execution_results:
|
| 924 |
+
# doc_url = execution_results['doc_url']
|
| 925 |
|
| 926 |
+
# # Respond to the user on WhatsApp with the processed idea
|
| 927 |
+
# response = message_back(processed_input, execution_status, doc_url, from_number)
|
| 928 |
+
# logger.debug(response)
|
| 929 |
|
| 930 |
+
# return JSONResponse(content=str(response))
|
| 931 |
+
# except Exception as e:
|
| 932 |
+
# logger.error(f"Error during task processing: {e}")
|
| 933 |
+
# return {"error": str(e)}
|
| 934 |
|
| 935 |
|
| 936 |
+
# # In[19]:
|
| 937 |
|
| 938 |
|
| 939 |
+
# # Mock Gmail Login Function
|
| 940 |
+
# def mock_login(email):
|
| 941 |
+
# if email.endswith("@gmail.com"):
|
| 942 |
+
# return f"✅ Logged in as {email}", gr.update(visible=False), gr.update(visible=True)
|
| 943 |
+
# else:
|
| 944 |
+
# return "❌ Invalid Gmail address. Please try again.", gr.update(), gr.update()
|
| 945 |
|
| 946 |
+
# # User Onboarding Function
|
| 947 |
+
# def onboarding_survey(role, industry, project_description):
|
| 948 |
+
# return (project_extraction(project_description),
|
| 949 |
+
# gr.update(visible=False), gr.update(visible=True))
|
| 950 |
|
| 951 |
+
# # Mock Integration Functions
|
| 952 |
+
# def integrate_todoist():
|
| 953 |
+
# return "✅ Successfully connected to Todoist!"
|
| 954 |
|
| 955 |
+
# def integrate_evernote():
|
| 956 |
+
# return "✅ Successfully connected to Evernote!"
|
| 957 |
|
| 958 |
+
# def integrate_calendar():
|
| 959 |
+
# return "✅ Successfully connected to Google Calendar!"
|
| 960 |
|
| 961 |
+
# def load_svg_with_size(file_path, width="600px", height="400px"):
|
| 962 |
+
# # Read the SVG content from the file
|
| 963 |
+
# with open(file_path, "r", encoding="utf-8") as file:
|
| 964 |
+
# svg_content = file.read()
|
| 965 |
|
| 966 |
+
# # Add inline styles to control width and height
|
| 967 |
+
# styled_svg = f"""
|
| 968 |
+
# <div style="width: {width}; height: {height}; overflow: auto;">
|
| 969 |
+
# {svg_content}
|
| 970 |
+
# </div>
|
| 971 |
+
# """
|
| 972 |
+
# return styled_svg
|
| 973 |
+
|
| 974 |
+
|
| 975 |
+
# # In[20]:
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
# # Gradio Demo
|
| 979 |
+
# def create_gradio_interface(state=None):
|
| 980 |
+
# with gr.Blocks(
|
| 981 |
+
# css="""
|
| 982 |
+
# .gradio-table td {
|
| 983 |
+
# white-space: normal !important;
|
| 984 |
+
# word-wrap: break-word !important;
|
| 985 |
+
# }
|
| 986 |
+
# .gradio-table {
|
| 987 |
+
# width: 100% !important; /* Adjust to 100% to fit the container */
|
| 988 |
+
# table-layout: fixed !important; /* Fixed column widths */
|
| 989 |
+
# overflow-x: hidden !important; /* Disable horizontal scrolling */
|
| 990 |
+
# }
|
| 991 |
+
# .gradio-container {
|
| 992 |
+
# overflow-x: hidden !important; /* Disable horizontal scroll for entire container */
|
| 993 |
+
# padding: 0 !important; /* Remove any default padding */
|
| 994 |
+
# }
|
| 995 |
+
# .gradio-column {
|
| 996 |
+
# max-width: 100% !important; /* Ensure columns take up full width */
|
| 997 |
+
# overflow: hidden !important; /* Hide overflow to prevent horizontal scroll */
|
| 998 |
+
# }
|
| 999 |
+
# .gradio-row {
|
| 1000 |
+
# overflow-x: hidden !important; /* Prevent horizontal scroll on rows */
|
| 1001 |
+
# }
|
| 1002 |
+
# """) as demo:
|
| 1003 |
+
|
| 1004 |
+
# # Page 1: Mock Gmail Login
|
| 1005 |
+
# with gr.Group(visible=True) as login_page:
|
| 1006 |
+
# gr.Markdown("### **1️⃣ Login with Gmail**")
|
| 1007 |
+
# email_input = gr.Textbox(label="Enter your Gmail Address", placeholder="[email protected]")
|
| 1008 |
+
# login_button = gr.Button("Login")
|
| 1009 |
+
# login_result = gr.Textbox(label="Login Status", interactive=False, visible=False)
|
| 1010 |
+
# # Page 2: User Onboarding
|
| 1011 |
+
# with gr.Group(visible=False) as onboarding_page:
|
| 1012 |
+
# gr.Markdown("### **2️⃣ Tell Us About Yourself**")
|
| 1013 |
+
# role = gr.Textbox(label="What is your role?", placeholder="e.g. Developer, Designer")
|
| 1014 |
+
# industry = gr.Textbox(label="Which industry are you in?", placeholder="e.g. Software, Finance")
|
| 1015 |
+
# project_description = gr.Textbox(label="Describe your project", placeholder="e.g. A task management app")
|
| 1016 |
+
# submit_survey = gr.Button("Submit")
|
| 1017 |
+
|
| 1018 |
+
# # Page 3: Mock Integrations with Separate Buttons
|
| 1019 |
+
# with gr.Group(visible=False) as integrations_page:
|
| 1020 |
+
# gr.Markdown("### **3️⃣ Connect Integrations**")
|
| 1021 |
+
# gr.Markdown("Click on the buttons below to connect each tool:")
|
| 1022 |
+
|
| 1023 |
+
# # Separate Buttons and Results for Each Integration
|
| 1024 |
+
# todoist_button = gr.Button("Connect to Todoist")
|
| 1025 |
+
# todoist_result = gr.Textbox(label="Todoist Status", interactive=False, visible=False)
|
| 1026 |
|
| 1027 |
+
# evernote_button = gr.Button("Connect to Evernote")
|
| 1028 |
+
# evernote_result = gr.Textbox(label="Evernote Status", interactive=False, visible=False)
|
| 1029 |
|
| 1030 |
+
# calendar_button = gr.Button("Connect to Google Calendar")
|
| 1031 |
+
# calendar_result = gr.Textbox(label="Google Calendar Status", interactive=False, visible=False)
|
| 1032 |
|
| 1033 |
+
# # Skip Button to proceed directly to next page
|
| 1034 |
+
# skip_integrations = gr.Button("Skip ➡️")
|
| 1035 |
+
# next_button = gr.Button("Proceed to QR Code")
|
| 1036 |
|
| 1037 |
+
# with gr.Group(visible=False) as qr_code_page:
|
| 1038 |
+
# # Page 4: QR Code and Curify Ideas
|
| 1039 |
+
# gr.Markdown("## Curify: Unified AI Tools for Productivity")
|
| 1040 |
|
| 1041 |
+
# with gr.Tab("Curify Idea"):
|
| 1042 |
+
# with gr.Row():
|
| 1043 |
+
# with gr.Column():
|
| 1044 |
+
# gr.Markdown("#### ** QR Code**")
|
| 1045 |
+
# # Path to your local SVG file
|
| 1046 |
+
# svg_file_path = "qr.svg"
|
| 1047 |
+
# # Load the SVG content
|
| 1048 |
+
# svg_content = load_svg_with_size(svg_file_path, width="200px", height="200px")
|
| 1049 |
+
# gr.HTML(svg_content)
|
| 1050 |
+
|
| 1051 |
+
# # Column 1: Webpage rendering
|
| 1052 |
+
# with gr.Column():
|
| 1053 |
|
| 1054 |
+
# gr.Markdown("## Projects Overview")
|
| 1055 |
+
# project_desc_table = gr.DataFrame(
|
| 1056 |
+
# type="pandas"
|
| 1057 |
+
# )
|
| 1058 |
+
|
| 1059 |
+
# gr.Markdown("## Enter task message.")
|
| 1060 |
+
# idea_input = gr.Textbox(
|
| 1061 |
+
# label=None,
|
| 1062 |
+
# placeholder="Describe the task you want to execute (e.g., Research Paper Review)")
|
| 1063 |
|
| 1064 |
+
# task_btn = gr.Button("Generate Task Steps")
|
| 1065 |
+
# fetch_state_btn = gr.Button("Fetch Updated State")
|
| 1066 |
+
|
| 1067 |
+
# with gr.Column():
|
| 1068 |
+
# gr.Markdown("## Task analysis")
|
| 1069 |
+
# task_analysis_txt = gr.Textbox(
|
| 1070 |
+
# label=None,
|
| 1071 |
+
# placeholder="Here is the execution status of your task...")
|
| 1072 |
+
|
| 1073 |
+
# gr.Markdown("## Execution status")
|
| 1074 |
+
# execution_status = gr.DataFrame(
|
| 1075 |
+
# type="pandas"
|
| 1076 |
+
# )
|
| 1077 |
+
# gr.Markdown("## Execution output")
|
| 1078 |
+
# execution_results = gr.JSON(
|
| 1079 |
+
# label=None
|
| 1080 |
+
# )
|
| 1081 |
+
# state_output = gr.State() # Add a state output to hold the state
|
| 1082 |
+
|
| 1083 |
+
# task_btn.click(
|
| 1084 |
+
# fn_process_task,
|
| 1085 |
+
# inputs=[project_desc_table, idea_input],
|
| 1086 |
+
# outputs=[task_analysis_txt, execution_status, execution_results]
|
| 1087 |
+
# )
|
| 1088 |
+
|
| 1089 |
+
# fetch_state_btn.click(
|
| 1090 |
+
# fetch_updated_state,
|
| 1091 |
+
# inputs=None,
|
| 1092 |
+
# outputs=[project_desc_table, task_analysis_txt, execution_status, execution_results]
|
| 1093 |
+
# )
|
| 1094 |
+
|
| 1095 |
+
# # Page 1 -> Page 2 Transition
|
| 1096 |
+
# login_button.click(
|
| 1097 |
+
# mock_login,
|
| 1098 |
+
# inputs=email_input,
|
| 1099 |
+
# outputs=[login_result, login_page, onboarding_page]
|
| 1100 |
+
# )
|
| 1101 |
+
|
| 1102 |
+
# # Page 2 -> Page 3 Transition (Submit and Skip)
|
| 1103 |
+
# submit_survey.click(
|
| 1104 |
+
# onboarding_survey,
|
| 1105 |
+
# inputs=[role, industry, project_description],
|
| 1106 |
+
# outputs=[project_desc_table, onboarding_page, integrations_page]
|
| 1107 |
+
# )
|
| 1108 |
+
|
| 1109 |
+
# # Integration Buttons
|
| 1110 |
+
# todoist_button.click(integrate_todoist, outputs=todoist_result)
|
| 1111 |
+
# evernote_button.click(integrate_evernote, outputs=evernote_result)
|
| 1112 |
+
# calendar_button.click(integrate_calendar, outputs=calendar_result)
|
| 1113 |
+
|
| 1114 |
+
# # Skip Integrations and Proceed
|
| 1115 |
+
# skip_integrations.click(
|
| 1116 |
+
# lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 1117 |
+
# outputs=[integrations_page, qr_code_page]
|
| 1118 |
+
# )
|
| 1119 |
+
|
| 1120 |
+
# # # Set the load_fn to initialize the state when the page is loaded
|
| 1121 |
+
# # demo.load(
|
| 1122 |
+
# # curify_ideas,
|
| 1123 |
+
# # inputs=[project_input, idea_input],
|
| 1124 |
+
# # outputs=[task_steps, task_analysis_txt, state_output]
|
| 1125 |
+
# # )
|
| 1126 |
+
# return demo
|
| 1127 |
+
# # Load function to initialize the state
|
| 1128 |
+
# # demo.load(load_fn, inputs=None, outputs=[state]) # Initialize the state when the page is loaded
|
| 1129 |
|
| 1130 |
|
| 1131 |
# In[21]:
|