MalikShehram commited on
Commit
1ed8f60
·
verified ·
1 Parent(s): d7b38c9

Update backend/ai_decoder.py

Browse files
Files changed (1) hide show
  1. backend/ai_decoder.py +13 -10
backend/ai_decoder.py CHANGED
@@ -1,19 +1,22 @@
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()
 
1
  import os
2
+ from huggingface_hub import InferenceClient
3
 
4
+ # We use Meta's Llama 3 model here, which is incredibly smart and completely FREE on Hugging Face!
5
+ client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
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 and absolutely nothing else."
9
+
10
+ messages = [
11
+ {"role": "system", "content": "You are a highly advanced 6G Semantic Communication Decoder. You output only the fixed sentence. No conversational text. No explanations."},
12
+ {"role": "user", "content": prompt}
13
+ ]
14
 
15
  try:
16
+ # Ask the free Hugging Face model to fix the text
17
+ response = client.chat_completion(
18
+ messages,
19
+ max_tokens=100,
 
 
20
  temperature=0.1
21
  )
22
  return response.choices[0].message.content.strip()