Spaces:
Sleeping
Sleeping
Update text_generator.py
Browse files- text_generator.py +20 -3
text_generator.py
CHANGED
@@ -9,21 +9,38 @@ class TextGenerationTool(Tool):
|
|
9 |
|
10 |
inputs = ["text"]
|
11 |
outputs = ["text"]
|
|
|
|
|
12 |
|
13 |
def __call__(self, prompt: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Replace the following line with your text generation logic
|
15 |
#generated_text = f"Generated text based on the prompt: '{prompt}'"
|
16 |
|
17 |
# Initialize the text generation pipeline
|
18 |
#text_generator = pipeline("text-generation") llama mistralai/Mistral-7B-Instruct-v0.1
|
19 |
-
text_generator = pipeline(model="gpt2")
|
20 |
#text_generator = pipeline(model="meta-llama/Llama-2-7b-chat-hf")
|
21 |
|
22 |
# Generate text based on a prompt
|
23 |
-
generated_text = text_generator(prompt, max_length=500, num_return_sequences=1, temperature=0.7)
|
24 |
|
25 |
# Print the generated text
|
26 |
-
print(generated_text)
|
27 |
|
28 |
|
29 |
|
|
|
9 |
|
10 |
inputs = ["text"]
|
11 |
outputs = ["text"]
|
12 |
+
|
13 |
+
import requests
|
14 |
|
15 |
def __call__(self, prompt: str):
|
16 |
+
|
17 |
+
|
18 |
+
API_URL = "https://api-inference.huggingface.co/models/lukasdrg/clinical_longformer_same_tokens_220k"
|
19 |
+
headers = {"Authorization": "Bearer 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"}
|
20 |
+
|
21 |
+
#def query(payload):
|
22 |
+
generated_text = requests.post(API_URL, headers=headers, json=payload)
|
23 |
+
# return response.json()
|
24 |
+
|
25 |
+
#output = query({
|
26 |
+
# "inputs": "The answer to the universe is <mask>.",
|
27 |
+
#})
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
# Replace the following line with your text generation logic
|
32 |
#generated_text = f"Generated text based on the prompt: '{prompt}'"
|
33 |
|
34 |
# Initialize the text generation pipeline
|
35 |
#text_generator = pipeline("text-generation") llama mistralai/Mistral-7B-Instruct-v0.1
|
36 |
+
#text_generator = pipeline(model="gpt2")
|
37 |
#text_generator = pipeline(model="meta-llama/Llama-2-7b-chat-hf")
|
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 |
|