Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -85,7 +85,7 @@ SERVER_URL = os.getenv("SERVER_URL", "https://your-huggingface-space-url.hf.spac
|
|
85 |
|
86 |
# Initialize OpenAI client
|
87 |
if OPENAI_API_KEY:
|
88 |
-
|
89 |
logger.info("✅ OpenAI client initialized successfully")
|
90 |
else:
|
91 |
logger.warning("⚠️ OpenAI API key not found - voice transcription will be disabled")
|
@@ -272,7 +272,7 @@ async def transcribe_voice_with_openai(file_path: str) -> str:
|
|
272 |
|
273 |
# First attempt with English-specific prompt and language restriction
|
274 |
with open(file_path, 'rb') as audio_file:
|
275 |
-
transcript =
|
276 |
model="whisper-1",
|
277 |
file=audio_file,
|
278 |
language="en", # Force English first
|
@@ -287,7 +287,7 @@ async def transcribe_voice_with_openai(file_path: str) -> str:
|
|
287 |
logger.warning(f"[Transcribe] First attempt failed, trying with Urdu-specific prompt")
|
288 |
|
289 |
with open(file_path, 'rb') as audio_file:
|
290 |
-
transcript =
|
291 |
model="whisper-1",
|
292 |
file=audio_file,
|
293 |
language="ur", # Force Urdu
|
@@ -302,7 +302,7 @@ async def transcribe_voice_with_openai(file_path: str) -> str:
|
|
302 |
logger.warning(f"[Transcribe] Second attempt failed, trying with mixed language prompt")
|
303 |
|
304 |
with open(file_path, 'rb') as audio_file:
|
305 |
-
transcript =
|
306 |
model="whisper-1",
|
307 |
file=audio_file,
|
308 |
prompt="This is a voice message for a veterinary products bot. Language: English or Urdu only. Common words: hi, hello, salam, one, two, three, aik, do, teen, search, browse, download, catalog, products, categories, contact, availability, hydropex, heposel, bromacid, tribiotic, symodex, adek gold. Please transcribe any speech you can hear, even if unclear. Numbers and menu selections are important."
|
@@ -2059,14 +2059,14 @@ Please provide:
|
|
2059 |
Format your response professionally with emojis and clear structure. Keep it concise but informative.
|
2060 |
"""
|
2061 |
|
2062 |
-
response =
|
2063 |
model="gpt-4o",
|
2064 |
messages=[{"role": "user", "content": prompt}],
|
2065 |
temperature=0.7,
|
2066 |
max_tokens=400
|
2067 |
)
|
2068 |
|
2069 |
-
ai_response = response.choices[0].message
|
2070 |
|
2071 |
# Add instructions for selection
|
2072 |
selection_instructions = (
|
@@ -2242,14 +2242,14 @@ If the query is outside the menu system, politely clarify and offer to return to
|
|
2242 |
Always keep responses professional, concise, and user-friendly.
|
2243 |
"""
|
2244 |
|
2245 |
-
response =
|
2246 |
model="gpt-4o",
|
2247 |
messages=[{"role": "user", "content": prompt}],
|
2248 |
temperature=0.7,
|
2249 |
max_tokens=300
|
2250 |
)
|
2251 |
|
2252 |
-
ai_response = response.choices[0].message
|
2253 |
|
2254 |
# Translate response if needed
|
2255 |
if reply_language == 'ur':
|
@@ -2767,14 +2767,14 @@ Response:
|
|
2767 |
"""
|
2768 |
|
2769 |
# Get AI response
|
2770 |
-
response =
|
2771 |
model="gpt-4o",
|
2772 |
messages=[{"role": "user", "content": prompt}],
|
2773 |
temperature=0.7,
|
2774 |
max_tokens=500
|
2775 |
)
|
2776 |
|
2777 |
-
ai_response = response.choices[0].message
|
2778 |
|
2779 |
# Add instructions for returning to main menu
|
2780 |
if reply_language == 'ur':
|
|
|
85 |
|
86 |
# Initialize OpenAI client
|
87 |
if OPENAI_API_KEY:
|
88 |
+
openai.api_key = OPENAI_API_KEY
|
89 |
logger.info("✅ OpenAI client initialized successfully")
|
90 |
else:
|
91 |
logger.warning("⚠️ OpenAI API key not found - voice transcription will be disabled")
|
|
|
272 |
|
273 |
# First attempt with English-specific prompt and language restriction
|
274 |
with open(file_path, 'rb') as audio_file:
|
275 |
+
transcript = openai.Audio.transcribe(
|
276 |
model="whisper-1",
|
277 |
file=audio_file,
|
278 |
language="en", # Force English first
|
|
|
287 |
logger.warning(f"[Transcribe] First attempt failed, trying with Urdu-specific prompt")
|
288 |
|
289 |
with open(file_path, 'rb') as audio_file:
|
290 |
+
transcript = openai.Audio.transcribe(
|
291 |
model="whisper-1",
|
292 |
file=audio_file,
|
293 |
language="ur", # Force Urdu
|
|
|
302 |
logger.warning(f"[Transcribe] Second attempt failed, trying with mixed language prompt")
|
303 |
|
304 |
with open(file_path, 'rb') as audio_file:
|
305 |
+
transcript = openai.Audio.transcribe(
|
306 |
model="whisper-1",
|
307 |
file=audio_file,
|
308 |
prompt="This is a voice message for a veterinary products bot. Language: English or Urdu only. Common words: hi, hello, salam, one, two, three, aik, do, teen, search, browse, download, catalog, products, categories, contact, availability, hydropex, heposel, bromacid, tribiotic, symodex, adek gold. Please transcribe any speech you can hear, even if unclear. Numbers and menu selections are important."
|
|
|
2059 |
Format your response professionally with emojis and clear structure. Keep it concise but informative.
|
2060 |
"""
|
2061 |
|
2062 |
+
response = openai.ChatCompletion.create(
|
2063 |
model="gpt-4o",
|
2064 |
messages=[{"role": "user", "content": prompt}],
|
2065 |
temperature=0.7,
|
2066 |
max_tokens=400
|
2067 |
)
|
2068 |
|
2069 |
+
ai_response = response.choices[0].message['content'].strip()
|
2070 |
|
2071 |
# Add instructions for selection
|
2072 |
selection_instructions = (
|
|
|
2242 |
Always keep responses professional, concise, and user-friendly.
|
2243 |
"""
|
2244 |
|
2245 |
+
response = openai.ChatCompletion.create(
|
2246 |
model="gpt-4o",
|
2247 |
messages=[{"role": "user", "content": prompt}],
|
2248 |
temperature=0.7,
|
2249 |
max_tokens=300
|
2250 |
)
|
2251 |
|
2252 |
+
ai_response = response.choices[0].message['content'].strip()
|
2253 |
|
2254 |
# Translate response if needed
|
2255 |
if reply_language == 'ur':
|
|
|
2767 |
"""
|
2768 |
|
2769 |
# Get AI response
|
2770 |
+
response = openai.ChatCompletion.create(
|
2771 |
model="gpt-4o",
|
2772 |
messages=[{"role": "user", "content": prompt}],
|
2773 |
temperature=0.7,
|
2774 |
max_tokens=500
|
2775 |
)
|
2776 |
|
2777 |
+
ai_response = response.choices[0].message['content'].strip()
|
2778 |
|
2779 |
# Add instructions for returning to main menu
|
2780 |
if reply_language == 'ur':
|