Spaces:
Sleeping
Sleeping
pravin007s
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -35,14 +35,14 @@ def translate_text(tamil_text):
|
|
35 |
except Exception as e:
|
36 |
return f"An error occurred: {str(e)}"
|
37 |
|
38 |
-
# API credentials and endpoint
|
39 |
-
|
40 |
-
|
41 |
|
42 |
# Function to send payload and generate image
|
43 |
def generate_image(prompt):
|
44 |
try:
|
45 |
-
response = requests.post(
|
46 |
|
47 |
# Check if the response is successful
|
48 |
if response.status_code == 200:
|
@@ -63,19 +63,23 @@ def generate_image(prompt):
|
|
63 |
print(f"An error occurred: {e}")
|
64 |
return None
|
65 |
|
66 |
-
#
|
67 |
-
|
|
|
68 |
|
69 |
-
# Load Mistral model and tokenizer
|
70 |
-
mistral_tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
|
71 |
-
mistral_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")
|
72 |
-
|
73 |
-
# Function to generate creative text based on translated text using Mistral
|
74 |
def generate_creative_text(translated_text):
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Function to handle the full workflow
|
81 |
def translate_generate_image_and_text(tamil_text):
|
|
|
35 |
except Exception as e:
|
36 |
return f"An error occurred: {str(e)}"
|
37 |
|
38 |
+
# API credentials and endpoint for FLUX
|
39 |
+
flux_API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
40 |
+
flux_headers = {"Authorization": f"Bearer {hf_token}"}
|
41 |
|
42 |
# Function to send payload and generate image
|
43 |
def generate_image(prompt):
|
44 |
try:
|
45 |
+
response = requests.post(flux_API_URL, headers=flux_headers, json={"inputs": prompt})
|
46 |
|
47 |
# Check if the response is successful
|
48 |
if response.status_code == 200:
|
|
|
63 |
print(f"An error occurred: {e}")
|
64 |
return None
|
65 |
|
66 |
+
# Function for Mistral API call to generate creative text
|
67 |
+
mistral_API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1"
|
68 |
+
mistral_headers = {"Authorization": f"Bearer {hf_token}"}
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
def generate_creative_text(translated_text):
|
71 |
+
try:
|
72 |
+
response = requests.post(mistral_API_URL, headers=mistral_headers, json={"inputs": translated_text})
|
73 |
+
if response.status_code == 200:
|
74 |
+
creative_text = response.json()[0]['generated_text']
|
75 |
+
return creative_text
|
76 |
+
else:
|
77 |
+
print(f"Failed to get creative text: Status code {response.status_code}")
|
78 |
+
print("Response content:", response.text) # Print response for debugging
|
79 |
+
return "Error generating creative text"
|
80 |
+
except Exception as e:
|
81 |
+
print(f"An error occurred: {e}")
|
82 |
+
return None
|
83 |
|
84 |
# Function to handle the full workflow
|
85 |
def translate_generate_image_and_text(tamil_text):
|