Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -825,56 +825,56 @@ def project_extraction(project_description):
|
|
| 825 |
|
| 826 |
# steps = store_and_execute_task(task_description, reasoning_path)
|
| 827 |
|
| 828 |
-
|
| 829 |
-
#
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
# # Format the body message
|
| 835 |
-
# body_message = (
|
| 836 |
-
# f"*Task Message:*\n{task_message}\n\n"
|
| 837 |
-
# f"*Execution Status:*\n{task_steps_list}\n\n"
|
| 838 |
-
# f"*Doc URL:*\n{doc_url}\n\n"
|
| 839 |
-
# )
|
| 840 |
-
|
| 841 |
-
# # Send response back to WhatsApp
|
| 842 |
-
# try:
|
| 843 |
-
# twillo_client.messages.create(
|
| 844 |
-
# from_=twilio_phone_number,
|
| 845 |
-
# to=from_whatsapp,
|
| 846 |
-
# body=body_message
|
| 847 |
-
# )
|
| 848 |
-
# except Exception as e:
|
| 849 |
-
# logger.error(f"Twilio Error: {e}")
|
| 850 |
-
# raise HTTPException(status_code=500, detail=f"Error sending WhatsApp message: {str(e)}")
|
| 851 |
|
| 852 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
|
| 854 |
-
#
|
| 855 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 856 |
|
| 857 |
-
|
| 858 |
-
# def transcribe_audio_from_media_url(media_url):
|
| 859 |
-
# try:
|
| 860 |
-
# media_response = requests.get(media_url, auth=HTTPBasicAuth(account_sid, auth_token))
|
| 861 |
-
# # Download the media file
|
| 862 |
-
# media_response.raise_for_status()
|
| 863 |
-
# audio_data = media_response.content
|
| 864 |
|
| 865 |
-
#
|
| 866 |
-
|
| 867 |
-
# with open(audio_file_path, "wb") as audio_file:
|
| 868 |
-
# audio_file.write(audio_data)
|
| 869 |
|
| 870 |
-
#
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
|
|
|
|
|
|
|
|
|
| 874 |
|
| 875 |
-
#
|
| 876 |
-
|
| 877 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
|
| 879 |
|
| 880 |
# In[18]:
|
|
@@ -882,277 +882,264 @@ def project_extraction(project_description):
|
|
| 882 |
|
| 883 |
app = FastAPI()
|
| 884 |
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
#
|
| 893 |
-
|
| 894 |
|
| 895 |
-
#
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
# # Initialize response variables
|
| 902 |
-
# transcription = None
|
| 903 |
-
|
| 904 |
-
# if media_type.startswith("audio"):
|
| 905 |
-
# # If the media is an audio or video file, process it
|
| 906 |
-
# try:
|
| 907 |
-
# transcription = transcribe_audio_from_media_url(media_url)
|
| 908 |
-
# except Exception as e:
|
| 909 |
-
# return JSONResponse(
|
| 910 |
-
# {"error": f"Failed to process voice input: {str(e)}"}, status_code=500
|
| 911 |
-
# )
|
| 912 |
-
# # Determine message content: use transcription if available, otherwise use text message
|
| 913 |
-
# processed_input = transcription if transcription else incoming_msg
|
| 914 |
|
| 915 |
-
#
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
#
|
| 920 |
-
|
| 921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
|
| 927 |
-
#
|
| 928 |
-
|
| 929 |
-
|
| 930 |
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
|
| 936 |
|
| 937 |
-
#
|
| 938 |
|
| 939 |
|
| 940 |
-
#
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
|
| 947 |
-
#
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
|
| 952 |
-
#
|
| 953 |
-
|
| 954 |
-
|
| 955 |
|
| 956 |
-
|
| 957 |
-
|
| 958 |
|
| 959 |
-
|
| 960 |
-
|
| 961 |
|
| 962 |
-
|
| 963 |
-
#
|
| 964 |
-
|
| 965 |
-
|
| 966 |
|
| 967 |
-
#
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
#
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
#
|
| 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 |
-
@app.on_event("startup")
|
| 1132 |
-
async def startup_event():
|
| 1133 |
-
logger.debug("Application startup initiated")
|
| 1134 |
-
# Simulate heavy operation
|
| 1135 |
-
# from transformers import pipeline
|
| 1136 |
-
# global model
|
| 1137 |
-
# model = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
|
| 1138 |
-
logger.debug("Application startup complete")
|
| 1139 |
|
| 1140 |
# In[21]:
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
# demo = create_gradio_interface()
|
| 1146 |
-
# # Use Gradio's `server_app` to get an ASGI app for Blocks
|
| 1147 |
-
# gradio_asgi_app = gr.routes.App.create_app(demo)
|
| 1148 |
|
| 1149 |
-
#
|
| 1150 |
-
|
| 1151 |
|
| 1152 |
-
#
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
|
| 1157 |
# Run the FastAPI server using uvicorn
|
| 1158 |
if __name__ == "__main__":
|
|
|
|
| 825 |
|
| 826 |
# steps = store_and_execute_task(task_description, reasoning_path)
|
| 827 |
|
| 828 |
+
def message_back(task_message, execution_status, doc_url, from_whatsapp):
|
| 829 |
+
# Convert task steps to a simple numbered list
|
| 830 |
+
task_steps_list = "\n".join(
|
| 831 |
+
[f"{i + 1}. {step['action']} - {step.get('output', '')}" for i, step in enumerate(execution_status.to_dict(orient="records"))]
|
| 832 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 833 |
|
| 834 |
+
# Format the body message
|
| 835 |
+
body_message = (
|
| 836 |
+
f"*Task Message:*\n{task_message}\n\n"
|
| 837 |
+
f"*Execution Status:*\n{task_steps_list}\n\n"
|
| 838 |
+
f"*Doc URL:*\n{doc_url}\n\n"
|
| 839 |
+
)
|
| 840 |
|
| 841 |
+
# Send response back to WhatsApp
|
| 842 |
+
try:
|
| 843 |
+
twillo_client.messages.create(
|
| 844 |
+
from_=twilio_phone_number,
|
| 845 |
+
to=from_whatsapp,
|
| 846 |
+
body=body_message
|
| 847 |
+
)
|
| 848 |
+
except Exception as e:
|
| 849 |
+
logger.error(f"Twilio Error: {e}")
|
| 850 |
+
raise HTTPException(status_code=500, detail=f"Error sending WhatsApp message: {str(e)}")
|
| 851 |
|
| 852 |
+
return {"status": "success"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
|
| 854 |
+
# Initialize the Whisper pipeline
|
| 855 |
+
whisper_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
|
|
|
|
|
|
|
| 856 |
|
| 857 |
+
# Function to transcribe audio from a media URL
|
| 858 |
+
def transcribe_audio_from_media_url(media_url):
|
| 859 |
+
try:
|
| 860 |
+
media_response = requests.get(media_url, auth=HTTPBasicAuth(account_sid, auth_token))
|
| 861 |
+
# Download the media file
|
| 862 |
+
media_response.raise_for_status()
|
| 863 |
+
audio_data = media_response.content
|
| 864 |
|
| 865 |
+
# Save the audio data to a file for processing
|
| 866 |
+
audio_file_path = "temp_audio_file.mp3"
|
| 867 |
+
with open(audio_file_path, "wb") as audio_file:
|
| 868 |
+
audio_file.write(audio_data)
|
| 869 |
+
|
| 870 |
+
# Transcribe the audio using Whisper
|
| 871 |
+
transcription = whisper_pipeline(audio_file_path, return_timestamps=True)
|
| 872 |
+
logger.debug(f"Transcription: {transcription['text']}")
|
| 873 |
+
return transcription["text"]
|
| 874 |
+
|
| 875 |
+
except Exception as e:
|
| 876 |
+
logger.error(f"An error occurred: {e}")
|
| 877 |
+
return None
|
| 878 |
|
| 879 |
|
| 880 |
# In[18]:
|
|
|
|
| 882 |
|
| 883 |
app = FastAPI()
|
| 884 |
|
| 885 |
+
@app.get("/state")
|
| 886 |
+
async def fetch_state():
|
| 887 |
+
return shared_state
|
| 888 |
|
| 889 |
+
@app.route("/whatsapp-webhook/", methods=["POST"])
|
| 890 |
+
async def whatsapp_webhook(request: Request):
|
| 891 |
+
form_data = await request.form()
|
| 892 |
+
# Log the form data to debug
|
| 893 |
+
print("Received data:", form_data)
|
| 894 |
|
| 895 |
+
# Extract message and user information
|
| 896 |
+
incoming_msg = form_data.get("Body", "").strip()
|
| 897 |
+
from_number = form_data.get("From", "")
|
| 898 |
+
media_url = form_data.get("MediaUrl0", "")
|
| 899 |
+
media_type = form_data.get("MediaContentType0", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
|
| 901 |
+
# Initialize response variables
|
| 902 |
+
transcription = None
|
| 903 |
+
|
| 904 |
+
if media_type.startswith("audio"):
|
| 905 |
+
# If the media is an audio or video file, process it
|
| 906 |
+
try:
|
| 907 |
+
transcription = transcribe_audio_from_media_url(media_url)
|
| 908 |
+
except Exception as e:
|
| 909 |
+
return JSONResponse(
|
| 910 |
+
{"error": f"Failed to process voice input: {str(e)}"}, status_code=500
|
| 911 |
+
)
|
| 912 |
+
# Determine message content: use transcription if available, otherwise use text message
|
| 913 |
+
processed_input = transcription if transcription else incoming_msg
|
| 914 |
+
|
| 915 |
+
logger.debug(f"Processed input: {processed_input}")
|
| 916 |
+
try:
|
| 917 |
+
# Generate response
|
| 918 |
+
project_desc_table, _ = fetch_updated_state()
|
| 919 |
+
if not project_desc_table.empty:
|
| 920 |
+
task_analysis_txt, execution_status, execution_results = fn_process_task(project_desc_table, processed_input)
|
| 921 |
+
update_gradio_state(task_analysis_txt, execution_status, execution_results)
|
| 922 |
|
| 923 |
+
doc_url = 'Fail to generate doc'
|
| 924 |
+
if 'doc_url' in execution_results:
|
| 925 |
+
doc_url = execution_results['doc_url']
|
| 926 |
|
| 927 |
+
# Respond to the user on WhatsApp with the processed idea
|
| 928 |
+
response = message_back(processed_input, execution_status, doc_url, from_number)
|
| 929 |
+
logger.debug(response)
|
| 930 |
|
| 931 |
+
return JSONResponse(content=str(response))
|
| 932 |
+
except Exception as e:
|
| 933 |
+
logger.error(f"Error during task processing: {e}")
|
| 934 |
+
return {"error": str(e)}
|
| 935 |
|
| 936 |
|
| 937 |
+
# In[19]:
|
| 938 |
|
| 939 |
|
| 940 |
+
# Mock Gmail Login Function
|
| 941 |
+
def mock_login(email):
|
| 942 |
+
if email.endswith("@gmail.com"):
|
| 943 |
+
return f"✅ Logged in as {email}", gr.update(visible=False), gr.update(visible=True)
|
| 944 |
+
else:
|
| 945 |
+
return "❌ Invalid Gmail address. Please try again.", gr.update(), gr.update()
|
| 946 |
|
| 947 |
+
# User Onboarding Function
|
| 948 |
+
def onboarding_survey(role, industry, project_description):
|
| 949 |
+
return (project_extraction(project_description),
|
| 950 |
+
gr.update(visible=False), gr.update(visible=True))
|
| 951 |
|
| 952 |
+
# Mock Integration Functions
|
| 953 |
+
def integrate_todoist():
|
| 954 |
+
return "✅ Successfully connected to Todoist!"
|
| 955 |
|
| 956 |
+
def integrate_evernote():
|
| 957 |
+
return "✅ Successfully connected to Evernote!"
|
| 958 |
|
| 959 |
+
def integrate_calendar():
|
| 960 |
+
return "✅ Successfully connected to Google Calendar!"
|
| 961 |
|
| 962 |
+
def load_svg_with_size(file_path, width="600px", height="400px"):
|
| 963 |
+
# Read the SVG content from the file
|
| 964 |
+
with open(file_path, "r", encoding="utf-8") as file:
|
| 965 |
+
svg_content = file.read()
|
| 966 |
|
| 967 |
+
# Add inline styles to control width and height
|
| 968 |
+
styled_svg = f"""
|
| 969 |
+
<div style="width: {width}; height: {height}; overflow: auto;">
|
| 970 |
+
{svg_content}
|
| 971 |
+
</div>
|
| 972 |
+
"""
|
| 973 |
+
return styled_svg
|
| 974 |
+
|
| 975 |
+
|
| 976 |
+
# In[20]:
|
| 977 |
+
|
| 978 |
+
|
| 979 |
+
# Gradio Demo
|
| 980 |
+
def create_gradio_interface(state=None):
|
| 981 |
+
with gr.Blocks(
|
| 982 |
+
css="""
|
| 983 |
+
.gradio-table td {
|
| 984 |
+
white-space: normal !important;
|
| 985 |
+
word-wrap: break-word !important;
|
| 986 |
+
}
|
| 987 |
+
.gradio-table {
|
| 988 |
+
width: 100% !important; /* Adjust to 100% to fit the container */
|
| 989 |
+
table-layout: fixed !important; /* Fixed column widths */
|
| 990 |
+
overflow-x: hidden !important; /* Disable horizontal scrolling */
|
| 991 |
+
}
|
| 992 |
+
.gradio-container {
|
| 993 |
+
overflow-x: hidden !important; /* Disable horizontal scroll for entire container */
|
| 994 |
+
padding: 0 !important; /* Remove any default padding */
|
| 995 |
+
}
|
| 996 |
+
.gradio-column {
|
| 997 |
+
max-width: 100% !important; /* Ensure columns take up full width */
|
| 998 |
+
overflow: hidden !important; /* Hide overflow to prevent horizontal scroll */
|
| 999 |
+
}
|
| 1000 |
+
.gradio-row {
|
| 1001 |
+
overflow-x: hidden !important; /* Prevent horizontal scroll on rows */
|
| 1002 |
+
}
|
| 1003 |
+
""") as demo:
|
| 1004 |
+
|
| 1005 |
+
# Page 1: Mock Gmail Login
|
| 1006 |
+
with gr.Group(visible=True) as login_page:
|
| 1007 |
+
gr.Markdown("### **1️⃣ Login with Gmail**")
|
| 1008 |
+
email_input = gr.Textbox(label="Enter your Gmail Address", placeholder="example@gmail.com")
|
| 1009 |
+
login_button = gr.Button("Login")
|
| 1010 |
+
login_result = gr.Textbox(label="Login Status", interactive=False, visible=False)
|
| 1011 |
+
# Page 2: User Onboarding
|
| 1012 |
+
with gr.Group(visible=False) as onboarding_page:
|
| 1013 |
+
gr.Markdown("### **2️⃣ Tell Us About Yourself**")
|
| 1014 |
+
role = gr.Textbox(label="What is your role?", placeholder="e.g. Developer, Designer")
|
| 1015 |
+
industry = gr.Textbox(label="Which industry are you in?", placeholder="e.g. Software, Finance")
|
| 1016 |
+
project_description = gr.Textbox(label="Describe your project", placeholder="e.g. A task management app")
|
| 1017 |
+
submit_survey = gr.Button("Submit")
|
| 1018 |
+
|
| 1019 |
+
# Page 3: Mock Integrations with Separate Buttons
|
| 1020 |
+
with gr.Group(visible=False) as integrations_page:
|
| 1021 |
+
gr.Markdown("### **3️⃣ Connect Integrations**")
|
| 1022 |
+
gr.Markdown("Click on the buttons below to connect each tool:")
|
| 1023 |
+
|
| 1024 |
+
# Separate Buttons and Results for Each Integration
|
| 1025 |
+
todoist_button = gr.Button("Connect to Todoist")
|
| 1026 |
+
todoist_result = gr.Textbox(label="Todoist Status", interactive=False, visible=False)
|
| 1027 |
|
| 1028 |
+
evernote_button = gr.Button("Connect to Evernote")
|
| 1029 |
+
evernote_result = gr.Textbox(label="Evernote Status", interactive=False, visible=False)
|
| 1030 |
|
| 1031 |
+
calendar_button = gr.Button("Connect to Google Calendar")
|
| 1032 |
+
calendar_result = gr.Textbox(label="Google Calendar Status", interactive=False, visible=False)
|
| 1033 |
|
| 1034 |
+
# Skip Button to proceed directly to next page
|
| 1035 |
+
skip_integrations = gr.Button("Skip ➡️")
|
| 1036 |
+
next_button = gr.Button("Proceed to QR Code")
|
| 1037 |
|
| 1038 |
+
with gr.Group(visible=False) as qr_code_page:
|
| 1039 |
+
# Page 4: QR Code and Curify Ideas
|
| 1040 |
+
gr.Markdown("## Curify: Unified AI Tools for Productivity")
|
| 1041 |
|
| 1042 |
+
with gr.Tab("Curify Idea"):
|
| 1043 |
+
with gr.Row():
|
| 1044 |
+
with gr.Column():
|
| 1045 |
+
gr.Markdown("#### ** QR Code**")
|
| 1046 |
+
# Path to your local SVG file
|
| 1047 |
+
svg_file_path = "qr.svg"
|
| 1048 |
+
# Load the SVG content
|
| 1049 |
+
svg_content = load_svg_with_size(svg_file_path, width="200px", height="200px")
|
| 1050 |
+
gr.HTML(svg_content)
|
| 1051 |
+
|
| 1052 |
+
# Column 1: Webpage rendering
|
| 1053 |
+
with gr.Column():
|
| 1054 |
|
| 1055 |
+
gr.Markdown("## Projects Overview")
|
| 1056 |
+
project_desc_table = gr.DataFrame(
|
| 1057 |
+
type="pandas"
|
| 1058 |
+
)
|
| 1059 |
+
|
| 1060 |
+
gr.Markdown("## Enter task message.")
|
| 1061 |
+
idea_input = gr.Textbox(
|
| 1062 |
+
label=None,
|
| 1063 |
+
placeholder="Describe the task you want to execute (e.g., Research Paper Review)")
|
| 1064 |
|
| 1065 |
+
task_btn = gr.Button("Generate Task Steps")
|
| 1066 |
+
fetch_state_btn = gr.Button("Fetch Updated State")
|
| 1067 |
+
|
| 1068 |
+
with gr.Column():
|
| 1069 |
+
gr.Markdown("## Task analysis")
|
| 1070 |
+
task_analysis_txt = gr.Textbox(
|
| 1071 |
+
label=None,
|
| 1072 |
+
placeholder="Here is the execution status of your task...")
|
| 1073 |
+
|
| 1074 |
+
gr.Markdown("## Execution status")
|
| 1075 |
+
execution_status = gr.DataFrame(
|
| 1076 |
+
type="pandas"
|
| 1077 |
+
)
|
| 1078 |
+
gr.Markdown("## Execution output")
|
| 1079 |
+
execution_results = gr.JSON(
|
| 1080 |
+
label=None
|
| 1081 |
+
)
|
| 1082 |
+
state_output = gr.State() # Add a state output to hold the state
|
| 1083 |
+
|
| 1084 |
+
task_btn.click(
|
| 1085 |
+
fn_process_task,
|
| 1086 |
+
inputs=[project_desc_table, idea_input],
|
| 1087 |
+
outputs=[task_analysis_txt, execution_status, execution_results]
|
| 1088 |
+
)
|
| 1089 |
+
|
| 1090 |
+
fetch_state_btn.click(
|
| 1091 |
+
fetch_updated_state,
|
| 1092 |
+
inputs=None,
|
| 1093 |
+
outputs=[project_desc_table, task_analysis_txt, execution_status, execution_results]
|
| 1094 |
+
)
|
| 1095 |
+
|
| 1096 |
+
# Page 1 -> Page 2 Transition
|
| 1097 |
+
login_button.click(
|
| 1098 |
+
mock_login,
|
| 1099 |
+
inputs=email_input,
|
| 1100 |
+
outputs=[login_result, login_page, onboarding_page]
|
| 1101 |
+
)
|
| 1102 |
+
|
| 1103 |
+
# Page 2 -> Page 3 Transition (Submit and Skip)
|
| 1104 |
+
submit_survey.click(
|
| 1105 |
+
onboarding_survey,
|
| 1106 |
+
inputs=[role, industry, project_description],
|
| 1107 |
+
outputs=[project_desc_table, onboarding_page, integrations_page]
|
| 1108 |
+
)
|
| 1109 |
+
|
| 1110 |
+
# Integration Buttons
|
| 1111 |
+
todoist_button.click(integrate_todoist, outputs=todoist_result)
|
| 1112 |
+
evernote_button.click(integrate_evernote, outputs=evernote_result)
|
| 1113 |
+
calendar_button.click(integrate_calendar, outputs=calendar_result)
|
| 1114 |
+
|
| 1115 |
+
# Skip Integrations and Proceed
|
| 1116 |
+
skip_integrations.click(
|
| 1117 |
+
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 1118 |
+
outputs=[integrations_page, qr_code_page]
|
| 1119 |
+
)
|
| 1120 |
+
|
| 1121 |
+
# # Set the load_fn to initialize the state when the page is loaded
|
| 1122 |
+
# demo.load(
|
| 1123 |
+
# curify_ideas,
|
| 1124 |
+
# inputs=[project_input, idea_input],
|
| 1125 |
+
# outputs=[task_steps, task_analysis_txt, state_output]
|
| 1126 |
+
# )
|
| 1127 |
+
return demo
|
| 1128 |
+
# Load function to initialize the state
|
| 1129 |
+
# demo.load(load_fn, inputs=None, outputs=[state]) # Initialize the state when the page is loaded
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
|
| 1131 |
# In[21]:
|
| 1132 |
+
demo = create_gradio_interface()
|
| 1133 |
+
# Use Gradio's `server_app` to get an ASGI app for Blocks
|
| 1134 |
+
gradio_asgi_app = gr.routes.App.create_app(demo)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1135 |
|
| 1136 |
+
# Mount the Gradio ASGI app at "/gradio"
|
| 1137 |
+
app.mount("/gradio", gradio_asgi_app)
|
| 1138 |
|
| 1139 |
+
# Redirect from the root endpoint to the Gradio app
|
| 1140 |
+
@app.get("/", response_class=RedirectResponse)
|
| 1141 |
+
async def index():
|
| 1142 |
+
return RedirectResponse(url="/gradio", status_code=307)
|
| 1143 |
|
| 1144 |
# Run the FastAPI server using uvicorn
|
| 1145 |
if __name__ == "__main__":
|