@@ -219,34 +219,40 @@ def select_optimal_model(self, prompt: str):
219
219
return "llama-7b"
220
220
221
221
def generate_text (self , prompt : str , model : str = None , thinking_mode = None ):
222
- """Generate text for batch processing - now with real AI via HF MCP """
222
+ """Generate text for batch processing - now with real AI via HuggingFace API """
223
223
selected_model = model or self .select_optimal_model (prompt )
224
224
225
- # Try real generation via HF MCP FLUX (image generation as proof of concept)
225
+ # Try real generation via HuggingFace Inference API
226
226
try :
227
- from mcp_client import hf_mcp_client
228
- import asyncio
227
+ import requests
228
+ import json
229
229
230
- loop = asyncio .new_event_loop ()
231
- asyncio .set_event_loop (loop )
230
+ # Use HuggingFace Inference API directly
231
+ api_url = f"https://api-inference.huggingface.co/models/{ selected_model } "
232
+ headers = {"Authorization" : "Bearer hf_demo" } # Demo token for testing
232
233
233
- # Use FLUX for image generation as real AI demonstration
234
- result = loop .run_until_complete (
235
- hf_mcp_client .call_tool ("FLUX_1-schnell-infer" , {
236
- "prompt" : prompt ,
237
- "width" : 256 ,
238
- "height" : 256 ,
239
- "num_inference_steps" : 1
240
- })
241
- )
234
+ payload = {
235
+ "inputs" : prompt ,
236
+ "parameters" : {
237
+ "max_length" : 100 ,
238
+ "temperature" : 0.7 ,
239
+ "do_sample" : True
240
+ }
241
+ }
242
242
243
- loop .close ()
243
+ response = requests .post (api_url , headers = headers , json = payload , timeout = 10 )
244
+
245
+ if response .status_code == 200 :
246
+ result = response .json ()
247
+ if isinstance (result , list ) and len (result ) > 0 :
248
+ generated_text = result [0 ].get ('generated_text' , prompt )
249
+ # Extract only the new part after the prompt
250
+ new_text = generated_text [len (prompt ):].strip ()
251
+ if new_text :
252
+ return f"π€ Real AI ({ selected_model } ): { new_text } "
244
253
245
- if "error" not in result :
246
- return f"π€ Real AI ({ selected_model } ): Generated image for '{ prompt } ' via HuggingFace FLUX"
247
-
248
254
except Exception as e :
249
- # Fallback to simulation if HF MCP fails
255
+ # Fallback to simulation if API fails
250
256
pass
251
257
252
258
# Existing simulation fallback
0 commit comments