Spaces:
Sleeping
Sleeping
Safwanahmad619
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -54,19 +54,18 @@
|
|
54 |
# )
|
55 |
|
56 |
# iface.launch()
|
57 |
-
|
58 |
import os
|
59 |
import gradio as gr
|
60 |
import whisper
|
61 |
from gtts import gTTS
|
62 |
-
from
|
63 |
import io # Import io for BytesIO
|
64 |
|
65 |
-
# Get the
|
66 |
-
|
67 |
-
if not
|
68 |
-
raise ValueError("
|
69 |
-
client =
|
70 |
|
71 |
# Load Whisper model
|
72 |
model = whisper.load_model("base")
|
@@ -80,12 +79,13 @@ def chatbot(audio=None):
|
|
80 |
transcription = model.transcribe(audio)
|
81 |
user_input = transcription.get("text", "")
|
82 |
|
83 |
-
# Generate a response using
|
84 |
-
chat_completion = client.
|
85 |
-
|
86 |
-
model="
|
|
|
87 |
)
|
88 |
-
response_text = chat_completion
|
89 |
|
90 |
# Convert the response text to speech using gTTS
|
91 |
tts = gTTS(text=response_text, lang='en')
|
|
|
54 |
# )
|
55 |
|
56 |
# iface.launch()
|
|
|
57 |
import os
|
58 |
import gradio as gr
|
59 |
import whisper
|
60 |
from gtts import gTTS
|
61 |
+
from anthropic import Anthropic # Import the Anthropic client
|
62 |
import io # Import io for BytesIO
|
63 |
|
64 |
+
# Get the Anthropic API key from environment variables
|
65 |
+
ANTHROPIC_API_KEY = os.getenv("anthropic_key")
|
66 |
+
if not ANTHROPIC_API_KEY:
|
67 |
+
raise ValueError("ANTHROPIC_API_KEY environment variable is not set.")
|
68 |
+
client = Anthropic(api_key=ANTHROPIC_API_KEY) # Initialize the Anthropic client
|
69 |
|
70 |
# Load Whisper model
|
71 |
model = whisper.load_model("base")
|
|
|
79 |
transcription = model.transcribe(audio)
|
80 |
user_input = transcription.get("text", "")
|
81 |
|
82 |
+
# Generate a response using Anthropic API
|
83 |
+
chat_completion = client.completions.create(
|
84 |
+
prompt=user_input,
|
85 |
+
model="claude-v1", # Replace with the correct model name for Anthropic
|
86 |
+
max_tokens=100, # Adjust as needed
|
87 |
)
|
88 |
+
response_text = chat_completion['completion']
|
89 |
|
90 |
# Convert the response text to speech using gTTS
|
91 |
tts = gTTS(text=response_text, lang='en')
|