Update backend/ai_decoder.py
Browse files- backend/ai_decoder.py +13 -10
backend/ai_decoder.py
CHANGED
|
@@ -1,19 +1,22 @@
|
|
| 1 |
import os
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
client =
|
| 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 |
-
|
| 12 |
-
|
| 13 |
-
messages
|
| 14 |
-
|
| 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()
|