Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,38 +42,39 @@ generation_pipeline = pipeline(
|
|
42 |
)
|
43 |
logger.info(f"Generation model loaded successfully: {generation_model_name}")
|
44 |
|
45 |
-
#
|
46 |
-
|
|
|
47 |
logger.info(f"Running classification for: {prompt[:50]}...")
|
48 |
-
|
49 |
-
loop = asyncio.get_event_loop()
|
50 |
-
classification_result = await loop.run_in_executor(
|
51 |
-
None,
|
52 |
-
lambda: classification_pipeline(prompt)
|
53 |
-
)
|
54 |
logger.info(f"Classification complete: {classification_result}")
|
55 |
return classification_result
|
56 |
|
57 |
-
#
|
58 |
-
|
|
|
59 |
logger.info(f"Running text generation for: {prompt[:50]}...")
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
do_sample=True,
|
67 |
-
temperature=0.7,
|
68 |
-
num_return_sequences=1
|
69 |
-
)
|
70 |
)
|
71 |
generated_text = generation_result[0]["generated_text"]
|
72 |
logger.info(f"Text generation complete, generated: {len(generated_text)} chars")
|
73 |
return generated_text
|
74 |
|
75 |
-
#
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
async def process_text_async(prompt):
|
78 |
logger.info(f"Processing input asynchronously: {prompt[:50]}...")
|
79 |
|
@@ -91,12 +92,18 @@ async def process_text_async(prompt):
|
|
91 |
combined_result = f"ๅ้ก็ตๆ: {classification_result}\n\n็ๆใใใใใญในใ: {generated_text}"
|
92 |
return combined_result
|
93 |
|
94 |
-
# Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
demo = gr.Interface(
|
96 |
-
fn=
|
97 |
inputs=gr.Textbox(lines=3, label="ๅ
ฅๅใใญในใ"),
|
98 |
outputs=gr.Textbox(label="ๅฆ็็ตๆ", lines=8),
|
99 |
-
title="ใใญในใๅ้ก & ็ๆใใข (
|
100 |
description="ๅ
ฅๅใใญในใใซๅฏพใใฆๅ้กใจ็ๆใ้ๅๆใงไธฆ่กๅฎ่กใใพใใ"
|
101 |
)
|
102 |
|
|
|
42 |
)
|
43 |
logger.info(f"Generation model loaded successfully: {generation_model_name}")
|
44 |
|
45 |
+
# GPUใๅฉ็จใใๅๆๅฆ็้ขๆฐ๏ผๅ้ก๏ผ
|
46 |
+
@spaces.GPU(duration=60)
|
47 |
+
def classify_text(prompt):
|
48 |
logger.info(f"Running classification for: {prompt[:50]}...")
|
49 |
+
classification_result = classification_pipeline(prompt)
|
|
|
|
|
|
|
|
|
|
|
50 |
logger.info(f"Classification complete: {classification_result}")
|
51 |
return classification_result
|
52 |
|
53 |
+
# GPUใๅฉ็จใใๅๆๅฆ็้ขๆฐ๏ผ็ๆ๏ผ
|
54 |
+
@spaces.GPU(duration=60)
|
55 |
+
def generate_text(prompt):
|
56 |
logger.info(f"Running text generation for: {prompt[:50]}...")
|
57 |
+
generation_result = generation_pipeline(
|
58 |
+
prompt,
|
59 |
+
max_new_tokens=50,
|
60 |
+
do_sample=True,
|
61 |
+
temperature=0.7,
|
62 |
+
num_return_sequences=1
|
|
|
|
|
|
|
|
|
63 |
)
|
64 |
generated_text = generation_result[0]["generated_text"]
|
65 |
logger.info(f"Text generation complete, generated: {len(generated_text)} chars")
|
66 |
return generated_text
|
67 |
|
68 |
+
# ้ๅๆใฉใใใผ้ขๆฐ
|
69 |
+
async def classify_text_async(prompt):
|
70 |
+
loop = asyncio.get_event_loop()
|
71 |
+
return await loop.run_in_executor(None, lambda: classify_text(prompt))
|
72 |
+
|
73 |
+
async def generate_text_async(prompt):
|
74 |
+
loop = asyncio.get_event_loop()
|
75 |
+
return await loop.run_in_executor(None, lambda: generate_text(prompt))
|
76 |
+
|
77 |
+
# ใกใคใณๅฆ็ใ่กใ้ๅๆ้ขๆฐ
|
78 |
async def process_text_async(prompt):
|
79 |
logger.info(f"Processing input asynchronously: {prompt[:50]}...")
|
80 |
|
|
|
92 |
combined_result = f"ๅ้ก็ตๆ: {classification_result}\n\n็ๆใใใใใญในใ: {generated_text}"
|
93 |
return combined_result
|
94 |
|
95 |
+
# Gradio็จใฎๅๆใฉใใใผ้ขๆฐ
|
96 |
+
def process_text(prompt):
|
97 |
+
# ้ๅๆ้ขๆฐใๅๆ็ใซๅฎ่ก
|
98 |
+
loop = asyncio.get_event_loop()
|
99 |
+
return loop.run_until_complete(process_text_async(prompt))
|
100 |
+
|
101 |
+
# Gradioใคใณใฟใผใใงใผใน
|
102 |
demo = gr.Interface(
|
103 |
+
fn=process_text, # ๅๆใฉใใใผ้ขๆฐใไฝฟ็จ
|
104 |
inputs=gr.Textbox(lines=3, label="ๅ
ฅๅใใญในใ"),
|
105 |
outputs=gr.Textbox(label="ๅฆ็็ตๆ", lines=8),
|
106 |
+
title="ใใญในใๅ้ก & ็ๆใใข (้ๅๆๅฆ็็)",
|
107 |
description="ๅ
ฅๅใใญในใใซๅฏพใใฆๅ้กใจ็ๆใ้ๅๆใงไธฆ่กๅฎ่กใใพใใ"
|
108 |
)
|
109 |
|