Spaces:
Runtime error
Runtime error
Update text_generator.py
Browse files- text_generator.py +25 -11
text_generator.py
CHANGED
@@ -14,23 +14,37 @@ class TextGenerationTool(Tool):
|
|
14 |
outputs = ["text"]
|
15 |
|
16 |
def __call__(self, prompt: str):
|
17 |
-
API_URL = "https://api-inference.huggingface.co/models/openchat/openchat_3.5"
|
18 |
-
headers = {"Authorization": "Bearer " + os.environ['hf']}
|
19 |
|
20 |
-
payload = {
|
21 |
-
|
22 |
-
}
|
23 |
|
24 |
-
payload = {
|
25 |
-
|
26 |
-
|
27 |
|
28 |
#def query(payload):
|
29 |
-
generated_text = requests.post(API_URL, headers=headers, json=payload).json()
|
30 |
-
print(generated_text)
|
31 |
-
return generated_text["text"]
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
34 |
|
35 |
# Define the payload for the request
|
36 |
#payload = {
|
|
|
14 |
outputs = ["text"]
|
15 |
|
16 |
def __call__(self, prompt: str):
|
17 |
+
#API_URL = "https://api-inference.huggingface.co/models/openchat/openchat_3.5"
|
18 |
+
#headers = {"Authorization": "Bearer " + os.environ['hf']}
|
19 |
|
20 |
+
#payload = {
|
21 |
+
# "inputs": prompt # Adjust this based on your model's input format
|
22 |
+
#}
|
23 |
|
24 |
+
#payload = {
|
25 |
+
# "inputs": "Can you please let us know more details about your ",
|
26 |
+
# }
|
27 |
|
28 |
#def query(payload):
|
29 |
+
#generated_text = requests.post(API_URL, headers=headers, json=payload).json()
|
30 |
+
#print(generated_text)
|
31 |
+
#return generated_text["text"]
|
32 |
|
33 |
+
# Replace the following line with your text generation logic
|
34 |
+
#generated_text = f"Generated text based on the prompt: '{prompt}'"
|
35 |
+
|
36 |
+
# Initialize the text generation pipeline
|
37 |
+
text_generator = pipeline(model="bigcode/starcoder")
|
38 |
+
|
39 |
+
# Generate text based on a prompt
|
40 |
+
generated_text = text_generator(prompt, max_length=500, num_return_sequences=1, temperature=0.7)
|
41 |
+
|
42 |
+
# Print the generated text
|
43 |
+
print(generated_text)
|
44 |
+
|
45 |
+
|
46 |
|
47 |
+
return generated_text
|
48 |
|
49 |
# Define the payload for the request
|
50 |
#payload = {
|