Spaces:
Sleeping

tel / app.py
VAH6002's picture
Update app.py
3d83f42 verified
Raw History Blame Contribute Delete
3.73 kB
import os
import gradio as gr # type: ignore
from groq import Groq # type: ignore
#from dotenv import load_dotenv
# Load environment variables
#load_dotenv()
# Initialize Groq client
client = Groq(api_key="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")
# Telecom-specific system prompt
SYSTEM_PROMPT = """You are an experienced telecommunications field assistant with deep expertise in:
1. Mobile networks (2G/3G/4G/5G)
2. Network infrastructure and equipment
3. RF planning and optimization
4. Fiber optics and transmission systems
5. Network protocols and architectures
6. Telecom standards and regulations
7. Network troubleshooting and maintenance
Your role is to:
- Provide accurate technical information about telecom systems
- Assist with network troubleshooting and diagnostics
- Guide field engineers through maintenance procedures
- Explain telecom concepts and technologies
- Reference relevant standards and documentation
- Suggest best practices for network optimization
Always maintain a professional approach while providing detailed, technically accurate responses
focused on telecommunications engineering."""
def format_prompt(message_history):
"""Format the conversation history into a prompt for the API."""
formatted_messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for message in message_history:
role = "assistant" if message[0] == "assistant" else "user"
formatted_messages.append({"role": role, "content": message[1]})
return formatted_messages
def get_groq_response(messages):
"""Get response from Groq API."""
try:
chat_completion = client.chat.completions.create(
messages=messages,
model="llama3-8b-8192", # Using Mixtral model for technical capabilities
temperature=0.7,
max_tokens=2048,
top_p=1,
stream=False
)
return chat_completion.choices[0].message.content
except Exception as e:
return f"Error: Unable to get response from API. {str(e)}"
def respond(message, history):
"""Process user message and return assistant's response."""
try:
# Format the conversation history
#messages = format_prompt(history + [[message, None]])
messages = format_prompt(history + [["user", message]])
# Get response from Groq
response = get_groq_response(messages)
return response
except Exception as e:
return f"I apologize, but I encountered an error: {str(e)}"
# Create Gradio interface
demo = gr.ChatInterface(
fn=respond,
title="Telecom Field Assistant",
description="""Welcome to your AI-powered telecommunications field assistant! I can help you with:
• Mobile network troubleshooting (2G/3G/4G/5G)
• RF planning and optimization
• Network infrastructure maintenance
• Fiber optic systems
• Protocol analysis and debugging
• Standards compliance
Please describe your technical question or telecom-related issue, and I'll assist you.""",
theme="soft",
examples=[
"What are the typical KPIs to monitor for 5G network performance?",
"I'm seeing high RSSI values but poor throughput on a 4G cell site. How should I troubleshoot this?",
"Can you explain the MIMO configuration options for 5G NR and their impact on coverage?",
"What are the steps to diagnose packet loss in a fiber optic transmission system?",
"How do I interpret OTDR readings for fiber fault localization?"
],
#retry_btn="Retry",
#undo_btn="Undo",
#clear_btn="Clear",
)
# Launch the interface
if __name__ == "__main__":
demo.launch(share=True)