yasserrmd commited on
Commit
32003ee
·
verified ·
1 Parent(s): 14fcdad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # Initialize the Hugging Face Inference Client
5
+ client = InferenceClient()
6
+
7
+ # Function to stream simplified text as it is generated
8
+ def simplify_text(input_text, audience):
9
+ prompt = f"Simplify the following text for a '{audience}' audience:\n\n{input_text}"
10
+
11
+ messages = [
12
+ {"role": "user", "content": prompt}
13
+ ]
14
+
15
+ # Create a stream to receive generated content
16
+ stream = client.chat.completions.create(
17
+ model="Qwen/QwQ-32B-Preview",
18
+ messages=messages,
19
+ temperature=0.7,
20
+ max_tokens=1024,
21
+ top_p=0.8,
22
+ stream=True
23
+ )
24
+
25
+ # Stream content as it is generated
26
+ simplified_output = ""
27
+ for chunk in stream:
28
+ simplified_output += chunk.choices[0].delta.content
29
+ yield simplified_output # Yield incremental content to display immediately
30
+
31
+ # Create Gradio interface with the modified layout
32
+ with gr.Blocks() as app:
33
+ gr.Markdown("## Contextual Text Simplifier")
34
+ gr.Markdown("Simplify complex text into context-appropriate language for specific audiences using AI.")
35
+
36
+ with gr.Row():
37
+ # First column for input components
38
+ with gr.Column():
39
+ text_input = gr.Textbox(
40
+ lines=6,
41
+ label="Input Text",
42
+ placeholder="Paste the text you want to simplify here.",
43
+ elem_id="full_width"
44
+ )
45
+ audience = gr.Dropdown(
46
+ choices=["Children", "General Public", "Professionals"],
47
+ label="Target Audience",
48
+ value="General Public"
49
+ )
50
+ simplify_button = gr.Button("Simplify Text")
51
+
52
+ # Second column for output
53
+ with gr.Column():
54
+ gr.Markdown("### Simplified Text") # This acts as the label for the output
55
+ output_markdown = gr.Markdown()
56
+
57
+ # Link button to function with inputs and outputs
58
+ simplify_button.click(fn=simplify_text, inputs=[text_input, audience], outputs=output_markdown)
59
+
60
+ # Run the Gradio app
61
+ app.launch(debug=True)