Onurcan Genç commited on
Commit ·
702c209
1
Parent(s): d555fd5
api integration
Browse files- app.py +12 -30
- requirements.txt +3 -2
app.py
CHANGED
|
@@ -1,45 +1,27 @@
|
|
| 1 |
import argparse
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
from
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
-
generator = pipeline("text-generation", model="gpt-neo-2.7B")
|
| 8 |
|
| 9 |
-
# Define a function to handle input and generate text
|
| 10 |
def generate_text(prompt):
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Define a function to handle input using OpenInterpreter
|
| 14 |
-
def generate_interpreter_response(prompt):
|
| 15 |
-
return interpreter.chat(prompt)
|
| 16 |
-
|
| 17 |
-
# CLI interface using argparse
|
| 18 |
def cli_interface():
|
| 19 |
-
parser = argparse.ArgumentParser(description="Command-line interaction with the
|
| 20 |
parser.add_argument("--task", type=str, help="The prompt or command to generate text for")
|
| 21 |
args = parser.parse_args()
|
| 22 |
|
| 23 |
-
# Provide a default task if none is provided
|
| 24 |
task = args.task if args.task else "Tell me a joke"
|
| 25 |
-
|
| 26 |
-
# Generate and print the result
|
| 27 |
result = generate_text(task)
|
| 28 |
print(result)
|
| 29 |
|
| 30 |
-
# Process task using OpenInterpreter
|
| 31 |
-
response = generate_interpreter_response(task)
|
| 32 |
-
print("OpenInterpreter Response:", response)
|
| 33 |
-
|
| 34 |
if __name__ == "__main__":
|
| 35 |
cli_interface()
|
| 36 |
-
|
| 37 |
-
# Additional information about the OpenInterpreter project
|
| 38 |
-
# OpenInterpreter allows LLMs to execute code (including Python, JavaScript, Shell commands, and more) in a local environment.
|
| 39 |
-
# It provides a natural-language interface to your computer's general-purpose capabilities, such as creating and editing files,
|
| 40 |
-
# controlling a web browser, and analyzing large datasets.
|
| 41 |
-
# To get started, install OpenInterpreter using:
|
| 42 |
-
# pip install open-interpreter
|
| 43 |
-
# After installation, start the interpreter with the command:
|
| 44 |
-
# $ interpreter
|
| 45 |
-
# For more information, visit: https://github.com/OpenInterpreter
|
|
|
|
| 1 |
import argparse
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def cli_interface():
|
| 18 |
+
parser = argparse.ArgumentParser(description="Command-line interaction with the deployed model.")
|
| 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)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
if __name__ == "__main__":
|
| 27 |
cli_interface()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
open-interpreter
|
| 3 |
torch
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
|
|
|
| 2 |
torch
|
| 3 |
+
python-dotenv
|
| 4 |
+
requests
|