pravin007s commited on
Commit
200834d
·
verified ·
1 Parent(s): b5054e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
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
- API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
40
- 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(API_URL, headers=headers, json={"inputs": prompt})
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
- # Import necessary libraries for Mistral model
67
- from transformers import AutoTokenizer, AutoModelForCausalLM
 
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
- input_ids = mistral_tokenizer(translated_text, return_tensors='pt').input_ids
76
- generated_text_ids = mistral_model.generate(input_ids, max_length=100)
77
- creative_text = mistral_tokenizer.decode(generated_text_ids[0], skip_special_tokens=True)
78
- return creative_text
 
 
 
 
 
 
 
 
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):