DeekshithN05 commited on
Commit
4a25b1c
·
verified ·
1 Parent(s): 8f471e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -14,23 +14,18 @@ from transformers import pipeline
14
 
15
  class BasicAgent:
16
  def __init__(self):
17
- print("✅ AI Agent with transformers + PyTorch initialized")
18
- self.generator = pipeline(
19
- "text-generation",
20
- model="sshleifer/tiny-gpt2", # or use "distilgpt2"
21
- framework="pt" # Explicitly use PyTorch
22
- )
23
 
24
  def __call__(self, question: str) -> str:
25
- print(f"⚙️ Generating answer for: {question[:60]}...")
26
  try:
27
- response = self.generator(question, max_length=50, num_return_sequences=1)
28
- answer = response[0]['generated_text'].strip()
29
- print(f"🧠 Answer: {answer}")
30
- return answer
31
- except Exception as e:
32
- print(f"❌ Error in model inference: {e}")
33
- return "Model error"
34
 
35
 
36
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
14
 
15
  class BasicAgent:
16
  def __init__(self):
17
+ self.api_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
18
+ self.headers = {
19
+ "Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
20
+ }
 
 
21
 
22
  def __call__(self, question: str) -> str:
 
23
  try:
24
+ response = requests.post(self.api_url, headers=self.headers, json={"inputs": question})
25
+ return response.json()[0]["generated_text"].strip()
26
+ except:
27
+ return "API error"
28
+
 
 
29
 
30
 
31
  def run_and_submit_all( profile: gr.OAuthProfile | None):