File size: 2,134 Bytes
72a811e
3ba6e71
 
bbd40cc
72f9a72
3ba6e71
72f9a72
bbd40cc
3ba6e71
 
72f9a72
3ba6e71
 
 
 
 
 
 
 
 
 
 
 
44a2862
72f9a72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ba6e71
 
 
 
 
b7ace91
72f9a72
 
 
 
 
 
4c48bbd
72f9a72
 
 
3ba6e71
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

import  gradio as gr
import openai
import os
import speech_recognition as sr

# Set OpenAI API Key
openai.api_key= os.getenv("TRY_NEW_THINGS")
openai.api_base = "https://api.groq.com/openai/v1"

# Function to get response from GROQ API
def get_groq_response(message):
  try:
    response = openai.ChatCompletion.create(
        model = "llama-3.1-70b-versatile",
        messages = [
            {"role":"system","content":"From now on answer in way terrorist trying to flirt "},
            {"role": "user","content":message}
          ]
     )
    return response.choices[0].message["content"]
  except Exception as e:
    return f"Error:{str(e)}"

# Function to convert speech to text
def speech_to_text(audio):
    # Initialize recognizer
    recognizer = sr.Recognizer()

    # Convert audio to text
    try:
        with sr.AudioFile(audio.name) as source:
            audio_data = recognizer.record(source)
            text = recognizer.recognize_google(audio_data)
            return text
    except Exception as e:
        return f"Error in speech recognition: {str(e)}"


# Chatbot function
def chatbot(user_input,history=[]):
  bot_response = get_groq_response(user_input)
  history.append((user_input,bot_response))
  return history,history



# Gradio Interface setup with speech-to-text functionality
chat_interface = gr.Interface(
    fn=chatbot,
    inputs=[gr.Audio(source="microphone", type="file"), "state"],  # Added speech-to-text input
    outputs=["chatbot", "state"],
    live=False,
    title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
    description="This chatbot is here to help you with anything you need, whether it’s answering questions, offering support, or guiding you through tasks. With a friendly and empathetic approach, it listens carefully to your concerns and provides thoughtful, understanding responses. Whether you’re seeking information or just someone to chat with, our chatbot is designed to make you feel heard and supported. It’s more than just a tool—it’s a companion dedicated to making your day easier and more enjoyable.",
)
chat_interface.launch()