anasfsd123 commited on
Commit
2cb0aad
·
verified ·
1 Parent(s): 8f6aefe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -8,13 +8,15 @@ import os
8
  import speech_recognition as sr
9
  from pydub import AudioSegment
10
  import tempfile
 
11
 
12
  # Configuration
13
  NASA_API_URL = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
14
  HF_MODEL_NAME = "all-MiniLM-L6-v2"
 
15
  HUGGINGFACE_API_TOKEN = os.getenv("HUGGINGFACE_API_KEY")
16
 
17
- # Set Hugging Face API token
18
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACE_API_TOKEN
19
 
20
  # Language Configuration
@@ -71,7 +73,6 @@ def load_knowledge_base():
71
  return None
72
 
73
  def setup_agents(language='en'):
74
- """Setup CrewAI agents with the correct LLM provider"""
75
  prompts = {
76
  'en': "Explain space concepts clearly in English",
77
  'es': "Explica conceptos espaciales en español",
@@ -86,11 +87,7 @@ def setup_agents(language='en'):
86
  goal="Analyze and validate space information",
87
  backstory="Expert in multilingual space data analysis with NASA mission experience.",
88
  verbose=True,
89
- llm={"model": "HuggingFaceH4/zephyr-7b-beta", "provider": "huggingface"},
90
- llm_kwargs={
91
- "temperature": 0.4,
92
- "max_length": 512
93
- },
94
  memory=True
95
  )
96
 
@@ -99,18 +96,13 @@ def setup_agents(language='en'):
99
  goal=f"Explain complex concepts in {language} using simple terms",
100
  backstory=f"Multilingual science communicator specializing in {language} explanations.",
101
  verbose=True,
102
- llm={"model": "HuggingFaceH4/zephyr-7b-beta", "provider": "huggingface"},
103
- llm_kwargs={
104
- "temperature": 0.5,
105
- "max_length": 612
106
- },
107
  memory=True
108
  )
109
 
110
  return researcher, educator
111
 
112
  def process_question(question, target_lang='en'):
113
- """Process the user's question using AI agents"""
114
  try:
115
  nasa_data = get_nasa_data()
116
  vector_store = load_knowledge_base()
@@ -143,7 +135,7 @@ def process_question(question, target_lang='en'):
143
  return f"Error: {str(e)}"
144
 
145
  # Streamlit Interface
146
- st.title("🚀COSMOLAB (Multilingual Space Agent)")
147
  st.markdown("### Ask space questions in any language!")
148
 
149
  # Single language selection for both input and output
@@ -167,9 +159,20 @@ else:
167
 
168
  if question:
169
  with st.spinner("Analyzing with AI agents..."):
170
- answer = process_question(question, lang_code)
171
- st.markdown(f"### 🌍 Answer ({selected_lang}):")
172
- st.markdown(answer)
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  st.markdown("---")
175
  st.markdown("Powered by NASA API & Open Source AI")
 
8
  import speech_recognition as sr
9
  from pydub import AudioSegment
10
  import tempfile
11
+ import litellm
12
 
13
  # Configuration
14
  NASA_API_URL = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
15
  HF_MODEL_NAME = "all-MiniLM-L6-v2"
16
+ LLM_MODEL = "huggingface/HuggingFaceH4/zephyr-7b-beta"
17
  HUGGINGFACE_API_TOKEN = os.getenv("HUGGINGFACE_API_KEY")
18
 
19
+ # Set Hugging Face API token in environment
20
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACE_API_TOKEN
21
 
22
  # Language Configuration
 
73
  return None
74
 
75
  def setup_agents(language='en'):
 
76
  prompts = {
77
  'en': "Explain space concepts clearly in English",
78
  'es': "Explica conceptos espaciales en español",
 
87
  goal="Analyze and validate space information",
88
  backstory="Expert in multilingual space data analysis with NASA mission experience.",
89
  verbose=True,
90
+ llm=LLM_MODEL,
 
 
 
 
91
  memory=True
92
  )
93
 
 
96
  goal=f"Explain complex concepts in {language} using simple terms",
97
  backstory=f"Multilingual science communicator specializing in {language} explanations.",
98
  verbose=True,
99
+ llm=LLM_MODEL,
 
 
 
 
100
  memory=True
101
  )
102
 
103
  return researcher, educator
104
 
105
  def process_question(question, target_lang='en'):
 
106
  try:
107
  nasa_data = get_nasa_data()
108
  vector_store = load_knowledge_base()
 
135
  return f"Error: {str(e)}"
136
 
137
  # Streamlit Interface
138
+ st.title("🚀 COSMOLAB (Multilingual Space Agent)")
139
  st.markdown("### Ask space questions in any language!")
140
 
141
  # Single language selection for both input and output
 
159
 
160
  if question:
161
  with st.spinner("Analyzing with AI agents..."):
162
+ try:
163
+ # Use litellm to get AI response
164
+ response = litellm.completion(
165
+ model=LLM_MODEL, # Correct model format
166
+ api_key=HUGGINGFACE_API_TOKEN, # Ensure API Key is passed
167
+ messages=[{"role": "user", "content": question}]
168
+ )
169
+ answer = response['choices'][0]['message']['content']
170
+
171
+ st.markdown(f"### 🌍 Answer ({selected_lang}):")
172
+ st.markdown(answer)
173
+
174
+ except Exception as e:
175
+ st.error(f"Error: {str(e)}")
176
 
177
  st.markdown("---")
178
  st.markdown("Powered by NASA API & Open Source AI")