oceansweep commited on
Commit
6d96d95
1 Parent(s): 488e282

Delete App_Function_Libraries/Tone-Changer.py

Browse files
App_Function_Libraries/Tone-Changer.py DELETED
@@ -1,46 +0,0 @@
1
- import gradio as gr
2
- import json
3
- from transformers import pipeline
4
-
5
- # Initialize the text generation pipeline
6
- generator = pipeline('text-generation', model='gpt2')
7
-
8
-
9
- def adjust_tone(text, concise, casual):
10
- tones = [
11
- {"tone": "concise", "weight": concise},
12
- {"tone": "casual", "weight": casual},
13
- {"tone": "professional", "weight": 1 - casual},
14
- {"tone": "expanded", "weight": 1 - concise}
15
- ]
16
- tones = sorted(tones, key=lambda x: x['weight'], reverse=True)[:2]
17
-
18
- tone_prompt = " and ".join([f"{t['tone']} (weight: {t['weight']:.2f})" for t in tones])
19
-
20
- prompt = f"Rewrite the following text to match these tones: {tone_prompt}. Text: {text}"
21
-
22
- result = generator(prompt, max_length=100, num_return_sequences=1)
23
- return result[0]['generated_text']
24
-
25
-
26
- # Gradio Interface
27
- with gr.Blocks() as demo:
28
- gr.Markdown("# Tone Adjuster")
29
-
30
- input_text = gr.Textbox(label="Input Text")
31
-
32
- with gr.Row():
33
- concise_slider = gr.Slider(minimum=0, maximum=1, value=0.5, label="Concise vs Expanded")
34
- casual_slider = gr.Slider(minimum=0, maximum=1, value=0.5, label="Casual vs Professional")
35
-
36
- output_text = gr.Textbox(label="Adjusted Text")
37
-
38
- adjust_btn = gr.Button("Adjust Tone")
39
-
40
- adjust_btn.click(
41
- adjust_tone,
42
- inputs=[input_text, concise_slider, casual_slider],
43
- outputs=output_text
44
- )
45
-
46
- demo.launch()