Onurcan Genç commited on
Commit
937e294
·
1 Parent(s): 702c209
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -6,11 +6,16 @@ from dotenv import load_dotenv
6
  load_dotenv() # Load environment variables from .env
7
 
8
  def generate_text(prompt):
9
- url = "https://api-inference.huggingface.co/models/drogba771/EleutherAI/gpt-j-6B" # Replace with your actual model URL
 
10
  headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
 
 
11
  response = requests.post(url, headers=headers, json={"inputs": prompt})
 
 
12
  if response.status_code == 200:
13
- return response.json()[0]["generated_text"]
14
  else:
15
  return f"Error: {response.status_code} - {response.text}"
16
 
@@ -19,6 +24,7 @@ def cli_interface():
19
  parser.add_argument("--task", type=str, help="The prompt or command to generate text for")
20
  args = parser.parse_args()
21
 
 
22
  task = args.task if args.task else "Tell me a joke"
23
  result = generate_text(task)
24
  print(result)
 
6
  load_dotenv() # Load environment variables from .env
7
 
8
  def generate_text(prompt):
9
+ # Use the correct model URL for EleutherAI's GPT-J 6B
10
+ url = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6b"
11
  headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
12
+
13
+ # Send the request with the prompt as input
14
  response = requests.post(url, headers=headers, json={"inputs": prompt})
15
+
16
+ # Check the response status and return the generated text if successful
17
  if response.status_code == 200:
18
+ return response.json()[0]["generated_text"] # Adjust for API's JSON structure
19
  else:
20
  return f"Error: {response.status_code} - {response.text}"
21
 
 
24
  parser.add_argument("--task", type=str, help="The prompt or command to generate text for")
25
  args = parser.parse_args()
26
 
27
+ # Use the provided prompt or default to "Tell me a joke"
28
  task = args.task if args.task else "Tell me a joke"
29
  result = generate_text(task)
30
  print(result)