File size: 1,836 Bytes
1fa66af
07f80e2
 
1fa66af
07f80e2
1fa66af
07f80e2
1fa66af
 
 
07f80e2
 
1fa66af
 
07f80e2
 
 
1fa66af
07f80e2
 
 
 
 
 
1fa66af
 
 
 
 
 
 
07f80e2
 
 
 
1fa66af
 
 
07f80e2
1fa66af
07f80e2
 
 
 
 
1fa66af
07f80e2
1fa66af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07f80e2
1fa66af
07f80e2
1fa66af
 
 
07f80e2
1fa66af
 
07f80e2
1fa66af
 
07f80e2
 
1fa66af
 
 
 
 
07f80e2
1fa66af
07f80e2
1fa66af
07f80e2
1fa66af
07f80e2
1fa66af
07f80e2
1fa66af
07f80e2
1fa66af
 
 
 
 
07f80e2
 
1fa66af
07f80e2
 
1fa66af
07f80e2
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import json
import gradio as gr
from huggingface_hub import InferenceClient

HF_TOKEN = os.getenv("HF_TOKEN")

client = InferenceClient(
    provider="hf-inference",
    api_key=HF_TOKEN
)

MODEL = "Qwen/Qwen2.5-3B-Instruct"

SYSTEM_PROMPT = """
You are Human Dynamics AI.

Analyze conversations objectively.

Return ONLY valid JSON.

Schema:

{
    "summary":"",
    "communication_style":"",
    "positive_patterns":[],
    "negative_patterns":[],
    "possible_risks":[],
    "coaching":[],
    "follow_up_message":""
}

Rules:

- Never diagnose people.
- Never claim certainty.
- Express risks as possibilities.
- Give practical coaching.
- Return JSON only.
"""


def analyze(conversation):

    try:

        response = client.chat_completion(
            model=MODEL,
            messages=[
                {
                    "role": "system",
                    "content": SYSTEM_PROMPT
                },
                {
                    "role": "user",
                    "content": conversation
                }
            ],
            max_tokens=700,
            temperature=0.4
        )

        result = response.choices[0].message.content

        try:
            parsed = json.loads(result)
            return json.dumps(parsed, indent=4)

        except Exception:
            return result

    except Exception as e:
        return f"Error:\n\n{e}"


demo = gr.Interface(
    fn=analyze,
    title="Human Dynamics AI",
    description="""
Paste any conversation.

The AI will return

• Summary

• Communication Style

• Positive Patterns

• Negative Patterns

• Possible Risks

• Coaching Suggestions

• Follow-up Message
""",
    inputs=gr.Textbox(
        lines=20,
        placeholder="Paste conversation here..."
    ),
    outputs=gr.Code(language="json")
)

demo.launch()