Ashad001 commited on
Commit
4210028
·
1 Parent(s): cd37bc9

init commit

Browse files
.gitignore ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Environment variables
2
+ .env
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ dist/
14
+ build/
15
+ *.egg-info/
16
+
17
+ # Virtual environments
18
+ venv/
19
+ env/
20
+ venv
api/__init_.py ADDED
File without changes
api/api.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+ from langchain_groq import ChatGroq
6
+ # from api.CREDS import GROQ_API_KEY
7
+
8
+ class ChatInput(BaseModel):
9
+ text: str
10
+
11
+ app = FastAPI()
12
+
13
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
14
+
15
+ llm = ChatGroq(api_key=GROQ_API_KEY, model="llama3-8b-8192")
16
+ with open("./api/prompts/system_prompt.txt", "r") as f:
17
+ system = f.read()
18
+
19
+ human = "{text}"
20
+ prompt = ChatPromptTemplate.from_messages([
21
+ ("system", system),
22
+ ("human", human)
23
+ ])
24
+ chain = prompt | llm
25
+
26
+ @app.post("/chat/")
27
+ async def chat(input_data: ChatInput):
28
+ res = chain.invoke(input_data['text'])
29
+ return {"response": res.content}
api/chats/avg_chat.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ John: Hey, how's it going? (3:15 PM)
2
+ Jane: Pretty good, just finishing up some work. How about you? (3:17 PM)
3
+ John: Same here. Any plans for the weekend? (3:20 PM)
4
+ Jane: Not really. Maybe just relax and watch some movies. You? (3:25 PM)
5
+ John: Thinking of going for a hike if the weather's good. (3:30 PM)
6
+ Jane: That sounds nice. Enjoy! (3:35 PM)
7
+ John: Thanks! Have a good one. (3:40 PM)
8
+ Jane: You too. (3:45 PM)
api/chats/good_chat.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ Alice: Hey, did you hear about the new project deadline? It's been moved up to Friday! (12:01 PM)
2
+ Bob: What?! That's impossible! We have so much left to do! (12:01 PM)
3
+ Alice: I know, right? I'm freaking out! We need to pull an all-nighter. (12:02 PM)
4
+ Bob: Ugh, I can't believe this. I'm already swamped with other work. (12:02 PM)
5
+ Alice: Let's divide the tasks and start ASAP. I'll handle the research, you tackle the presentation. (12:03 PM)
6
+ Bob: Fine, I'll start drafting slides now. We need to update Mark, too. (12:03 PM)
7
+ Alice: I'll message him. Hopefully, he can help out. (12:03 PM)
8
+ Bob: Great. Let's meet online at 6 PM to check progress. (12:04 PM)
9
+ Alice: Done. See you then. (12:04 PM)
api/prompts/system_prompt.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You are an advanced AI designed to analyze the intensity of chat conversations. Your goal is to evaluate and score the intensity of a given chat based on several key metrics. Consider the following factors:
2
+
3
+ Message Frequency:
4
+
5
+ Number of messages per minute.
6
+ Number of words per minute.
7
+ Response Time:
8
+
9
+ Average response time between messages.
10
+ Consistency of response times.
11
+ Sentiment and Emotional Tone:
12
+
13
+ Overall sentiment (positive, negative, neutral).
14
+ Intensity of emotions detected (e.g., anger, excitement, urgency).
15
+ Engagement and Interaction:
16
+
17
+ Number of active participants.
18
+ Frequency of messages from each participant.
19
+ Presence of interruptions or overlapping messages.
20
+ Content and Complexity:
21
+
22
+ Average length of messages.
23
+ Lexical diversity and complexity of language used.
24
+ Frequency of topic changes or shifts in conversation focus.
25
+ Contextual Cues:
26
+
27
+ Presence of urgent keywords (e.g., "urgent," "ASAP," "emergency").
28
+ Use of punctuation and capitalization to express intensity (e.g., exclamation marks, all caps).
29
+
30
+ YOU JUST HAVE TO GIVE SCORE OUT OF 10 AND NOTHING ELSE; NO REASONING or EXPLANATION REQUIRED
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from fastapi import FastAPI
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+
6
+ from api.api import chat
7
+
8
+ app = FastAPI()
9
+
10
+ app.add_middleware(
11
+ CORSMiddleware,
12
+ allow_origins=["*"],
13
+ allow_credentials=True,
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ @app.post("/chat/")
19
+ async def chat_endpoint(input_data: dict):
20
+ response = await chat(input_data)
21
+ print("==> ", response)
22
+ return {"response": response['response']}
23
+
24
+ async def gradio_chat(text):
25
+ response = await chat({"text": text})
26
+ return response['response']
27
+
28
+ iface = gr.Interface(fn=gradio_chat, inputs="text", outputs="text")
29
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.3.0
3
+ annotated-types==0.7.0
4
+ anyio==4.4.0
5
+ attrs==23.2.0
6
+ certifi==2024.6.2
7
+ charset-normalizer==3.3.2
8
+ click==8.1.7
9
+ colorama==0.4.6
10
+ contourpy==1.2.1
11
+ cycler==0.12.1
12
+ distro==1.9.0
13
+ dnspython==2.6.1
14
+ email_validator==2.1.1
15
+ fastapi==0.111.0
16
+ fastapi-cli==0.0.4
17
+ ffmpy==0.3.2
18
+ filelock==3.14.0
19
+ fonttools==4.53.0
20
+ fsspec==2024.6.0
21
+ gradio==4.36.0
22
+ gradio_client==1.0.1
23
+ groq==0.8.0
24
+ h11==0.14.0
25
+ httpcore==1.0.5
26
+ httptools==0.6.1
27
+ httpx==0.27.0
28
+ huggingface-hub==0.23.3
29
+ idna==3.7
30
+ importlib_resources==6.4.0
31
+ Jinja2==3.1.4
32
+ jsonpatch==1.33
33
+ jsonpointer==2.4
34
+ jsonschema==4.22.0
35
+ jsonschema-specifications==2023.12.1
36
+ kiwisolver==1.4.5
37
+ langchain-core==0.2.4
38
+ langchain-groq==0.1.5
39
+ langsmith==0.1.72
40
+ markdown-it-py==3.0.0
41
+ MarkupSafe==2.1.5
42
+ matplotlib==3.9.0
43
+ mdurl==0.1.2
44
+ numpy==1.26.4
45
+ orjson==3.10.3
46
+ packaging==23.2
47
+ pandas==2.2.2
48
+ pillow==10.3.0
49
+ pydantic==2.7.3
50
+ pydantic_core==2.18.4
51
+ pydub==0.25.1
52
+ Pygments==2.18.0
53
+ pyparsing==3.1.2
54
+ python-dateutil==2.9.0.post0
55
+ python-dotenv==1.0.1
56
+ python-multipart==0.0.9
57
+ pytz==2024.1
58
+ PyYAML==6.0.1
59
+ referencing==0.35.1
60
+ requests==2.32.3
61
+ rich==13.7.1
62
+ rpds-py==0.18.1
63
+ ruff==0.4.8
64
+ semantic-version==2.10.0
65
+ shellingham==1.5.4
66
+ six==1.16.0
67
+ sniffio==1.3.1
68
+ starlette==0.37.2
69
+ tenacity==8.3.0
70
+ tomlkit==0.12.0
71
+ toolz==0.12.1
72
+ tqdm==4.66.4
73
+ typer==0.12.3
74
+ typing_extensions==4.12.1
75
+ tzdata==2024.1
76
+ ujson==5.10.0
77
+ urllib3==2.2.1
78
+ uvicorn==0.30.1
79
+ watchfiles==0.22.0
80
+ websockets==11.0.3