Th3Nic3Guy commited on
Commit
7ffcdf9
·
1 Parent(s): 022fe4f

innitial deploy

Browse files
Files changed (3) hide show
  1. .gitignore +11 -0
  2. app.py +105 -0
  3. requirements.txt +7 -0
.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .venv/
2
+ .xenv/
3
+ api.json
4
+ *.ipynb
5
+ .ipynb_checkpoints/
6
+ .vscode/
7
+ __pycache__/
8
+ *.pyc
9
+ *.pyo
10
+ *.pyd
11
+
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """gradio app for Chat Interface for DataStax Langflow calls"""
2
+
3
+ import json
4
+ from typing import Optional, Sequence, Tuple
5
+ from uuid import uuid4
6
+ import requests
7
+ import gradio as gr
8
+ import os
9
+
10
+ BASE_API_URL = "https://api.langflow.astra.datastax.com"
11
+ LANGFLOW_ID = "e99b525a-84dd-4cf2-bac6-8e5ebc6a7d17"
12
+ FLOW_ID = "bfbf7237-50dd-40dd-baba-cc680288d788"
13
+ APPLICATION_TOKEN = os.getenv('DATASTAX_TOKEN')
14
+
15
+ ENDPOINT = 'ai_traveller'
16
+ # SESSION_ID = str(uuid4())
17
+
18
+ TWEAKS = {
19
+ "Memory-fCuCs": {
20
+ "n_messages": 100,
21
+ "order": "Ascending",
22
+ "sender": "Machine and User",
23
+ "sender_name": "",
24
+ "template": "{sender_name}: {text}"
25
+ },
26
+ "ChatInput-PN5E4": {},
27
+ "Prompt-vGvVG": {},
28
+ "GoogleGenerativeAIModel-6n0Ft": {},
29
+ "ChatOutput-HjfF1": {}
30
+ }
31
+
32
+
33
+ def call_travel_ai(
34
+ message: str,
35
+ history: Sequence[Tuple[str, str]],
36
+ session_id: str,
37
+ endpoint: str = ENDPOINT,
38
+ output_type: str = "chat",
39
+ input_type: str = "chat",
40
+ tweaks: Optional[dict] = None,
41
+ application_token: Optional[str] = APPLICATION_TOKEN
42
+ ) -> dict:
43
+ """
44
+ Run a flow with a given message and optional tweaks.
45
+
46
+ :param message: The message to send to the flow
47
+ :param endpoint: The ID or the endpoint name of the flow
48
+ :param tweaks: Optional tweaks to customize the flow
49
+ :return: The JSON response from the flow
50
+ """
51
+ api_url = f"{BASE_API_URL}/lf/{LANGFLOW_ID}/api/v1/run/{endpoint}"
52
+
53
+ payload = {
54
+ 'session_id': session_id,
55
+ "input_value": message,
56
+ "output_type": output_type,
57
+ "input_type": input_type,
58
+ }
59
+ headers = None
60
+ if tweaks:
61
+ payload["tweaks"] = tweaks
62
+ if application_token:
63
+ headers = {
64
+ "Authorization": "Bearer " + application_token,
65
+ "Content-Type": "application/json"
66
+ }
67
+ response = requests.post(
68
+ api_url,
69
+ json=payload,
70
+ headers=headers,
71
+ timeout=360
72
+ )
73
+ response = response.json()
74
+ resp_message = ''
75
+ for resp in response['outputs']:
76
+ for _resp in resp['outputs']:
77
+ for message in _resp['messages']:
78
+ resp_message = message['message']
79
+
80
+ return resp_message
81
+
82
+ def generate_session_id():
83
+ return str(uuid4())
84
+
85
+ def render_value(value):
86
+ return value
87
+
88
+ with gr.Blocks() as demo:
89
+ session_id = gr.Textbox(
90
+ value=generate_session_id,
91
+ visible=False,
92
+ interactive=False,
93
+ label="Session ID",
94
+ )
95
+
96
+ chat_interface = gr.ChatInterface(
97
+ call_travel_ai,
98
+ type='messages',
99
+ title=f"AI Travel Partner",
100
+ additional_inputs=[session_id],
101
+ autofocus=True,
102
+ fill_height=True,
103
+ )
104
+
105
+ demo.launch(share=False, debug=True,)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ google-genai
4
+ # langflow
5
+ langchain
6
+ requests
7
+ gradio