Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# prompt: currently the image generation function starts after user give a single letter. but for user friendly reason it should start to process after user gives his entrie input. here generate button is big make it small
|
2 |
-
|
3 |
from transformers import pipeline
|
4 |
import gradio as gr
|
5 |
# from diffusers import DiffusionPipeline
|
@@ -13,9 +11,13 @@ from PIL import Image
|
|
13 |
|
14 |
# Load models
|
15 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-dra-en")
|
16 |
-
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
17 |
# image_pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.float16).to("cpu")
|
18 |
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
# for image api
|
@@ -37,8 +39,28 @@ def translate_tamil_to_english(text):
|
|
37 |
# Summarize English Paragraph
|
38 |
def summarize_english_text(paragraph):
|
39 |
time.sleep(2)
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
# Generate image from English text
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
# from diffusers import DiffusionPipeline
|
|
|
11 |
|
12 |
# Load models
|
13 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-dra-en")
|
14 |
+
# summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
15 |
# image_pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.float16).to("cpu")
|
16 |
|
17 |
+
# for summarizer api
|
18 |
+
SUMMARIZER_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
19 |
+
summarizer_headers = {"Authorization": f"Bearer {os.getenv('GROQ_API_TOKEN')}",
|
20 |
+
"Content-Type": "application/json"}
|
21 |
|
22 |
|
23 |
# for image api
|
|
|
39 |
# Summarize English Paragraph
|
40 |
def summarize_english_text(paragraph):
|
41 |
time.sleep(2)
|
42 |
+
# Request payload
|
43 |
+
payload = {
|
44 |
+
"model": "mixtral-8x7b-32768",
|
45 |
+
"messages": [
|
46 |
+
{"role": "system", "content": "Create a summary of below paragraph in 30 words max"},
|
47 |
+
{"role": "user", "content": paragraph}
|
48 |
+
],
|
49 |
+
"max_tokens": 100 # number of words in the output.
|
50 |
+
}
|
51 |
+
|
52 |
+
# Send POST request to Groq API
|
53 |
+
response = requests.post(SUMMARIZER_API_URL, json=payload, headers=summarizer_headers)
|
54 |
+
|
55 |
+
# Check if the request was successful
|
56 |
+
if response.status_code == 200:
|
57 |
+
# Parse the JSON response
|
58 |
+
result = response.json()
|
59 |
+
# Extract and print the generated text
|
60 |
+
generated_text = result['choices'][0]['message']['content']
|
61 |
+
return generated_text
|
62 |
+
else:
|
63 |
+
return f"Error: {response.status_code}, {response.text}"
|
64 |
|
65 |
|
66 |
# Generate image from English text
|