saherPervaiz commited on
Commit
6cf385e
·
verified ·
1 Parent(s): f795d3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -2,15 +2,13 @@ import os
2
  import gradio as gr
3
  from groq import Groq
4
  from googletrans import Translator
5
- import asyncio
6
 
7
  # Function to get recommendations from Groq AI based on user input
8
  def get_opportunities(user_interests, user_skills, user_location):
9
- # Fetch the API key from the environment variable
10
- api_key = "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"
11
 
12
  if not api_key:
13
- raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
14
 
15
  # Initialize the Groq client with the API key
16
  client = Groq(api_key=api_key)
@@ -26,19 +24,18 @@ def get_opportunities(user_interests, user_skills, user_location):
26
 
27
  return response.choices[0].message.content
28
 
29
- # Function to translate text into the selected language (async version)
30
- async def translate_text(text, target_language):
31
  translator = Translator()
32
- translated = await translator.translate(text, dest=target_language)
33
  return translated.text
34
 
35
  # Function to get chatbot response
36
  def get_chatbot_response(user_message):
37
- # Fetch the API key from the environment variable
38
- api_key = "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"
39
 
40
  if not api_key:
41
- raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
42
 
43
  # Initialize the Groq client with the API key
44
  client = Groq(api_key=api_key)
@@ -110,7 +107,7 @@ with gr.Blocks(css="""
110
  def find_opportunities_and_chat(interests, skills, location, language, user_message):
111
  # Fetch opportunities
112
  opportunities = get_opportunities(interests, skills, location)
113
- translated_opportunities = asyncio.run(translate_text(opportunities, language))
114
 
115
  # Get chatbot response
116
  chatbot_response = get_chatbot_response(user_message) if user_message else "Ask me anything!"
 
2
  import gradio as gr
3
  from groq import Groq
4
  from googletrans import Translator
 
5
 
6
  # Function to get recommendations from Groq AI based on user input
7
  def get_opportunities(user_interests, user_skills, user_location):
8
+ api_key = "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" # Replace with your actual API key
 
9
 
10
  if not api_key:
11
+ raise ValueError("API key is missing.")
12
 
13
  # Initialize the Groq client with the API key
14
  client = Groq(api_key=api_key)
 
24
 
25
  return response.choices[0].message.content
26
 
27
+ # Function to translate text into the selected language
28
+ def translate_text(text, target_language):
29
  translator = Translator()
30
+ translated = translator.translate(text, dest=target_language)
31
  return translated.text
32
 
33
  # Function to get chatbot response
34
  def get_chatbot_response(user_message):
35
+ api_key = "your_groq_api_key" # Replace with your actual API key
 
36
 
37
  if not api_key:
38
+ raise ValueError("API key is missing.")
39
 
40
  # Initialize the Groq client with the API key
41
  client = Groq(api_key=api_key)
 
107
  def find_opportunities_and_chat(interests, skills, location, language, user_message):
108
  # Fetch opportunities
109
  opportunities = get_opportunities(interests, skills, location)
110
+ translated_opportunities = translate_text(opportunities, language)
111
 
112
  # Get chatbot response
113
  chatbot_response = get_chatbot_response(user_message) if user_message else "Ask me anything!"