MalikShehram commited on
Commit
1d98141
·
verified ·
1 Parent(s): cb8104c

Update backend/ai_decoder.py

Browse files
Files changed (1) hide show
  1. backend/ai_decoder.py +11 -14
backend/ai_decoder.py CHANGED
@@ -1,24 +1,21 @@
1
  import os
2
- from huggingface_hub import InferenceClient
3
 
4
- # Initialize the client (Reads from HF_TOKEN environment variable)
5
- client = InferenceClient(api_key=os.getenv("HF_TOKEN"))
6
 
7
  def decode_semantic_intent(corrupted_text: str) -> str:
8
- prompt = f"""You are a 6G Semantic Communication Decoder.
9
- A message was mathematically destroyed by wireless noise.
10
- The traditional mathematical demodulator outputted this gibberish: '{corrupted_text}'
11
-
12
- Based on linguistic probability, reconstruct the original intent of the message perfectly.
13
- Only output the corrected sentence. Do not add any conversational text."""
14
 
15
  try:
16
- response = client.text_generation(
17
- prompt,
18
- model="mistralai/Mistral-7B-Instruct-v0.2",
19
- max_new_tokens=50,
 
 
20
  temperature=0.1
21
  )
22
- return response.strip()
23
  except Exception as e:
24
  return f"AI Decoding Failed: {str(e)}"
 
1
  import os
2
+ from openai import OpenAI
3
 
4
+ # Automatically reads the OPENAI_API_KEY from your Space Secrets
5
+ client = OpenAI()
6
 
7
  def decode_semantic_intent(corrupted_text: str) -> str:
8
+ prompt = f"A message was destroyed by wireless noise. The demodulator outputted: '{corrupted_text}'. Reconstruct the original intent perfectly. Only output the corrected sentence."
 
 
 
 
 
9
 
10
  try:
11
+ response = client.chat.completions.create(
12
+ model="gpt-4o-mini",
13
+ messages=[
14
+ {"role": "system", "content": "You are a 6G Semantic Communication Decoder."},
15
+ {"role": "user", "content": prompt}
16
+ ],
17
  temperature=0.1
18
  )
19
+ return response.choices[0].message.content.strip()
20
  except Exception as e:
21
  return f"AI Decoding Failed: {str(e)}"