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()