Spaces:
Runtime error
Runtime error
syedfarith
commited on
Commit
•
b3e77db
1
Parent(s):
2086da4
Upload 3 files
Browse files- Dockerfile +14 -0
- app.py +66 -0
- requirements.txt +82 -0
Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.15
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
+
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
10 |
+
|
11 |
+
COPY --chown=user . /app
|
12 |
+
CMD ["chainlit", "run", "app.py", "--port", "7860"]
|
13 |
+
|
14 |
+
# CMD ["chainlit", "run", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chainlit as cl
|
2 |
+
from groq import Groq
|
3 |
+
from langdetect import detect
|
4 |
+
from deep_translator import GoogleTranslator
|
5 |
+
|
6 |
+
# Initialize the Groq client
|
7 |
+
client = Groq(api_key="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")
|
8 |
+
LITERAL_API_KEY="lsk_A8YDyASs7LnDbfIoACnbXAgkSL0i2lC27htdkXUD0k"
|
9 |
+
|
10 |
+
import chainlit as cl
|
11 |
+
|
12 |
+
@cl.set_starters
|
13 |
+
async def set_starters():
|
14 |
+
return [
|
15 |
+
cl.Starter(
|
16 |
+
label="Morning routine ideation",
|
17 |
+
message="Can you help me create a personalized morning routine that would help increase my productivity throughout the day? Start by asking me about my current habits and what activities energize me in the morning.",
|
18 |
+
),
|
19 |
+
|
20 |
+
cl.Starter(
|
21 |
+
label="Explain superconductors",
|
22 |
+
message="Explain superconductors like I'm five years old.",
|
23 |
+
),
|
24 |
+
cl.Starter(
|
25 |
+
label="Python script for daily email reports",
|
26 |
+
message="Write a script to automate sending daily email reports in Python, and walk me through how I would set it up.",
|
27 |
+
),
|
28 |
+
cl.Starter(
|
29 |
+
label="Text inviting friend to wedding",
|
30 |
+
message="Write a text asking a friend to be my plus-one at a wedding next month. I want to keep it super short and casual, and offer an out.",
|
31 |
+
)
|
32 |
+
]
|
33 |
+
|
34 |
+
@cl.on_message
|
35 |
+
async def main(message: cl.Message):
|
36 |
+
# Detect the language of the input message
|
37 |
+
detected_language = detect(message.content)
|
38 |
+
|
39 |
+
# If the detected language is not English, translate the message to English
|
40 |
+
if detected_language != "en":
|
41 |
+
input_text = GoogleTranslator(source=detected_language, target="en").translate(message.content)
|
42 |
+
else:
|
43 |
+
input_text = message.content
|
44 |
+
|
45 |
+
# Create a chat completion request
|
46 |
+
chat_completion = client.chat.completions.create(
|
47 |
+
messages=[
|
48 |
+
{
|
49 |
+
"role": "user",
|
50 |
+
"content": input_text,
|
51 |
+
}
|
52 |
+
],
|
53 |
+
model="llama3-8b-8192",
|
54 |
+
)
|
55 |
+
|
56 |
+
# Get the response from the model
|
57 |
+
response_text = chat_completion.choices[0].message.content
|
58 |
+
|
59 |
+
# If the input was translated to English, translate the response back to the detected language
|
60 |
+
if detected_language != "en":
|
61 |
+
response_text = GoogleTranslator(source="en", target=detected_language).translate(response_text)
|
62 |
+
|
63 |
+
# Send the response back to the user
|
64 |
+
await cl.Message(
|
65 |
+
content=response_text
|
66 |
+
).send()
|
requirements.txt
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==3.7.1
|
4 |
+
asyncer==0.0.2
|
5 |
+
asyncpg==0.29.0
|
6 |
+
beautifulsoup4==4.12.3
|
7 |
+
bidict==0.23.1
|
8 |
+
certifi==2024.6.2
|
9 |
+
chainlit==1.1.301
|
10 |
+
chardet==3.0.4
|
11 |
+
charset-normalizer==3.3.2
|
12 |
+
chevron==0.14.0
|
13 |
+
click==8.1.7
|
14 |
+
colorama==0.4.6
|
15 |
+
dataclasses-json==0.5.14
|
16 |
+
deep-translator==1.11.4
|
17 |
+
Deprecated==1.2.14
|
18 |
+
distro==1.9.0
|
19 |
+
dnspython==2.6.1
|
20 |
+
fastapi==0.110.3
|
21 |
+
filetype==1.2.0
|
22 |
+
googleapis-common-protos==1.63.1
|
23 |
+
googletrans==3.1.0a0
|
24 |
+
groq==0.9.0
|
25 |
+
grpcio==1.64.1
|
26 |
+
h11==0.14.0
|
27 |
+
h2==3.2.0
|
28 |
+
hpack==3.0.0
|
29 |
+
hstspreload==2024.6.1
|
30 |
+
httpcore==1.0.5
|
31 |
+
httpx==0.27.0
|
32 |
+
hyperframe==5.2.0
|
33 |
+
idna==2.10
|
34 |
+
importlib_metadata==7.1.0
|
35 |
+
langdetect==1.0.9
|
36 |
+
Lazify==0.4.0
|
37 |
+
literalai==0.0.604
|
38 |
+
marshmallow==3.21.3
|
39 |
+
motor==3.4.0
|
40 |
+
mypy-extensions==1.0.0
|
41 |
+
nest-asyncio==1.6.0
|
42 |
+
numpy==1.26.4
|
43 |
+
opentelemetry-api==1.25.0
|
44 |
+
opentelemetry-exporter-otlp==1.25.0
|
45 |
+
opentelemetry-exporter-otlp-proto-common==1.25.0
|
46 |
+
opentelemetry-exporter-otlp-proto-grpc==1.25.0
|
47 |
+
opentelemetry-exporter-otlp-proto-http==1.25.0
|
48 |
+
opentelemetry-instrumentation==0.46b0
|
49 |
+
opentelemetry-proto==1.25.0
|
50 |
+
opentelemetry-sdk==1.25.0
|
51 |
+
opentelemetry-semantic-conventions==0.46b0
|
52 |
+
packaging==23.2
|
53 |
+
protobuf==4.25.3
|
54 |
+
pydantic==2.7.4
|
55 |
+
pydantic_core==2.18.4
|
56 |
+
PyJWT==2.8.0
|
57 |
+
pymongo==4.7.3
|
58 |
+
python-dotenv==1.0.1
|
59 |
+
python-engineio==4.9.1
|
60 |
+
python-multipart==0.0.9
|
61 |
+
python-socketio==5.11.2
|
62 |
+
requests==2.32.3
|
63 |
+
rfc3986==1.5.0
|
64 |
+
setuptools==70.0.0
|
65 |
+
simple-websocket==1.0.0
|
66 |
+
six==1.16.0
|
67 |
+
sniffio==1.3.1
|
68 |
+
soupsieve==2.5
|
69 |
+
starlette==0.37.2
|
70 |
+
syncer==2.0.3
|
71 |
+
tomli==2.0.1
|
72 |
+
typing-inspect==0.9.0
|
73 |
+
typing_extensions==4.12.2
|
74 |
+
uptrace==1.24.0
|
75 |
+
urllib3==2.2.1
|
76 |
+
uvicorn==0.25.0
|
77 |
+
watchfiles==0.20.0
|
78 |
+
wrapt==1.16.0
|
79 |
+
wsproto==1.2.0
|
80 |
+
zipp==3.19.2
|
81 |
+
fastapi
|
82 |
+
uvicorn[standard]
|