Spaces:
Sleeping
Sleeping
Commit
·
088c542
1
Parent(s):
2c64b23
test
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from langdetect import detect
|
|
7 |
# Load a summarization model
|
8 |
summarizer = pipeline("summarization")
|
9 |
|
|
|
|
|
|
|
10 |
def text_analysis(text):
|
11 |
# Analyze text: word count, character count, language detection, and readability
|
12 |
words = re.findall(r'\w+', text.lower())
|
@@ -31,7 +34,12 @@ def text_summarization(text):
|
|
31 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
32 |
return summary
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
text_analysis_interface = gr.Interface(fn=text_analysis,
|
36 |
inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
|
37 |
outputs=gr.JSON(label="Text Analysis"))
|
@@ -40,10 +48,12 @@ text_summarization_interface = gr.Interface(fn=text_summarization,
|
|
40 |
inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
|
41 |
outputs="text")
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
# Launch the
|
48 |
if __name__ == "__main__":
|
|
|
49 |
text_summarization_interface.launch()
|
|
|
|
7 |
# Load a summarization model
|
8 |
summarizer = pipeline("summarization")
|
9 |
|
10 |
+
# Load a text generation model from Hugging Face
|
11 |
+
text_generator = pipeline("text-generation", model="gpt2")
|
12 |
+
|
13 |
def text_analysis(text):
|
14 |
# Analyze text: word count, character count, language detection, and readability
|
15 |
words = re.findall(r'\w+', text.lower())
|
|
|
34 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
35 |
return summary
|
36 |
|
37 |
+
def generate_text(prompt):
|
38 |
+
# Generate text using the loaded Hugging Face model
|
39 |
+
generated_text = text_generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
|
40 |
+
return generated_text
|
41 |
+
|
42 |
+
# Define interfaces for text analysis, text summarization, and text generation
|
43 |
text_analysis_interface = gr.Interface(fn=text_analysis,
|
44 |
inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
|
45 |
outputs=gr.JSON(label="Text Analysis"))
|
|
|
48 |
inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
|
49 |
outputs="text")
|
50 |
|
51 |
+
text_generation_interface = gr.Interface(fn=generate_text,
|
52 |
+
inputs=gr.Textbox(lines=4, placeholder="Type a prompt..."),
|
53 |
+
outputs="text")
|
54 |
|
55 |
+
# Launch the interfaces
|
56 |
if __name__ == "__main__":
|
57 |
+
text_analysis_interface.launch()
|
58 |
text_summarization_interface.launch()
|
59 |
+
text_generation_interface.launch()
|