Spaces:
Sleeping
Sleeping
Rename text_generator.py to random_charactor_generator.py
Browse files- random_charactor_generator.py +73 -0
- text_generator.py +0 -45
random_charactor_generator.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
class RandomCharacterTool:
|
4 |
+
name = "random_character"
|
5 |
+
description = "This tool fetches a random character from the 'https://randomuser.me/api/' open API."
|
6 |
+
|
7 |
+
outputs = ["character"]
|
8 |
+
|
9 |
+
def __call__(self):
|
10 |
+
API_URL = "https://randomuser.me/api/"
|
11 |
+
|
12 |
+
response = requests.get(API_URL)
|
13 |
+
data = response.json()['results'][0]
|
14 |
+
|
15 |
+
# Extract the relevant character information
|
16 |
+
character = {
|
17 |
+
"gender": data['gender'],
|
18 |
+
"name": {
|
19 |
+
"title": data['name']['title'],
|
20 |
+
"first": data['name']['first'],
|
21 |
+
"last": data['name']['last']
|
22 |
+
},
|
23 |
+
"location": {
|
24 |
+
"street": {
|
25 |
+
"number": data['location']['street']['number'],
|
26 |
+
"name": data['location']['street']['name']
|
27 |
+
},
|
28 |
+
"city": data['location']['city'],
|
29 |
+
"state": data['location']['state'],
|
30 |
+
"country": data['location']['country'],
|
31 |
+
"postcode": data['location']['postcode'],
|
32 |
+
"coordinates": {
|
33 |
+
"latitude": data['location']['coordinates']['latitude'],
|
34 |
+
"longitude": data['location']['coordinates']['longitude']
|
35 |
+
},
|
36 |
+
"timezone": {
|
37 |
+
"offset": data['location']['timezone']['offset'],
|
38 |
+
"description": data['location']['timezone']['description']
|
39 |
+
}
|
40 |
+
},
|
41 |
+
"email": data['email'],
|
42 |
+
"login": {
|
43 |
+
"uuid": data['login']['uuid'],
|
44 |
+
"username": data['login']['username'],
|
45 |
+
"password": data['login']['password'],
|
46 |
+
"salt": data['login']['salt'],
|
47 |
+
"md5": data['login']['md5'],
|
48 |
+
"sha1": data['login']['sha1'],
|
49 |
+
"sha256": data['login']['sha256']
|
50 |
+
},
|
51 |
+
"dob": {
|
52 |
+
"date": data['dob']['date'],
|
53 |
+
"age": data['dob']['age']
|
54 |
+
},
|
55 |
+
"registered": {
|
56 |
+
"date": data['registered']['date'],
|
57 |
+
"age": data['registered']['age']
|
58 |
+
},
|
59 |
+
"phone": data['phone'],
|
60 |
+
"cell": data['cell'],
|
61 |
+
"id": {
|
62 |
+
"name": data['id']['name'],
|
63 |
+
"value": data['id']['value']
|
64 |
+
},
|
65 |
+
"picture": {
|
66 |
+
"large": data['picture']['large'],
|
67 |
+
"medium": data['picture']['medium'],
|
68 |
+
"thumbnail": data['picture']['thumbnail']
|
69 |
+
},
|
70 |
+
"nat": data['nat']
|
71 |
+
}
|
72 |
+
|
73 |
+
return {"character": character}
|
text_generator.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import os
|
3 |
-
|
4 |
-
from transformers import Tool
|
5 |
-
# Import other necessary libraries if needed
|
6 |
-
|
7 |
-
class TextGenerationTool(Tool):
|
8 |
-
name = "text_generator"
|
9 |
-
description = (
|
10 |
-
"This is a tool for text generation. It takes a prompt as input and returns the generated text."
|
11 |
-
)
|
12 |
-
|
13 |
-
inputs = ["text"]
|
14 |
-
outputs = ["text"]
|
15 |
-
|
16 |
-
def __call__(self, prompt: str):
|
17 |
-
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1"
|
18 |
-
headers = {"Authorization": os.environ['hf']}
|
19 |
-
|
20 |
-
def query(payload):
|
21 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
22 |
-
print(response)
|
23 |
-
return response.json()
|
24 |
-
|
25 |
-
output = query({
|
26 |
-
"inputs": prompt,
|
27 |
-
})
|
28 |
-
|
29 |
-
# Define the payload for the request
|
30 |
-
#payload = {
|
31 |
-
# "inputs": prompt # Adjust this based on your model's input format
|
32 |
-
#}
|
33 |
-
|
34 |
-
# Make the request to the API
|
35 |
-
#generated_text = requests.post(API_URL, headers=headers, json=payload).json()
|
36 |
-
|
37 |
-
# Extract and return the generated text
|
38 |
-
#return generated_text["generated_text"]
|
39 |
-
|
40 |
-
# Uncomment and customize the following lines based on your text generation needs
|
41 |
-
# text_generator = pipeline(model="gpt2")
|
42 |
-
# generated_text = text_generator(prompt, max_length=500, num_return_sequences=1, temperature=0.7)
|
43 |
-
|
44 |
-
# Print the generated text if needed
|
45 |
-
# print(generated_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|