Spaces:
Sleeping
Sleeping
Delete appy.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344from azure.ai.textanalytics import TextAnalyticsClientfrom azure.core.credentials import AzureKeyCredentialfrom transformers import AutoModelForCausalLM, AutoTokenizer
# Azure Text Analytics setupazure_endpoint = "https://t6langservice.cognitiveservices.azure.com/"azure_api_key = "3CU1gpUszvl7pLb90Ivdp1Kd5WZc56savzdXOK5GV40JHebnxnxoJQQJ99BAACYeBjFXJ3w3AAAaACOGkRT5"
# Authenticate clienttext_analytics_client = TextAnalyticsClient(endpoint=azure_endpoint, credential=AzureKeyCredential(azure_api_key))
# Load Hugging Face chatbot modelmodel_name = "microsoft/DialoGPT-medium"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)
# Chatbot logicdef chatbot_response(input_text): # Hugging Face response input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt") chat_output = model.generate(input_ids, max_length=50, pad_token_id=tokenizer.eos_token_id) hf_response = tokenizer.decode(chat_output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
# Azure Text Analytics: Analyze sentiment of user input try: response = text_analytics_client.analyze_sentiment([input_text])[0] sentiment = response.sentiment azure_analysis = f"The sentiment of your input is: {sentiment}." except Exception as e: azure_analysis = f"Error analyzing sentiment: {str(e)}"
# Combine responses return f"Hugging Face response: {hf_response}\nAzure analysis: {azure_analysis}"
# Chat loopwhile True: user_input = input("You: ") if user_input.lower() in ["exit", "quit"]: print("Exiting chatbot. Goodbye!") break print(chatbot_response(user_input))
appy.pyDeleted-44