Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 debate arguments as they are generated
|
| 8 |
+
def debate_stream(topic, stance):
|
| 9 |
+
prompt = f"Construct a logical argument for the topic: '{topic}' with a stance: '{stance}'. Include both supporting arguments and potential counterarguments."
|
| 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="AIDC-AI/Marco-o1",
|
| 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 |
+
debate_output = ""
|
| 27 |
+
for chunk in stream:
|
| 28 |
+
debate_output += chunk.choices[0].delta.content
|
| 29 |
+
yield debate_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("## Automated Debate System")
|
| 34 |
+
gr.Markdown("Generate logical arguments and counterarguments for any debate topic using advanced AI reasoning.")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
# First column for input components
|
| 38 |
+
with gr.Column():
|
| 39 |
+
topic_input = gr.Textbox(lines=2, label="Debate Topic", placeholder="Enter your debate topic here", elem_id="full_width")
|
| 40 |
+
stance = gr.Dropdown(
|
| 41 |
+
choices=["For", "Against"],
|
| 42 |
+
label="Stance",
|
| 43 |
+
value="For"
|
| 44 |
+
)
|
| 45 |
+
debate_button = gr.Button("Generate Debate Arguments")
|
| 46 |
+
|
| 47 |
+
# Second column for output
|
| 48 |
+
with gr.Column():
|
| 49 |
+
gr.Markdown("### Debate Arguments") # This acts as the label for the output
|
| 50 |
+
output_markdown = gr.Markdown()
|
| 51 |
+
|
| 52 |
+
# Link button to function with inputs and outputs
|
| 53 |
+
debate_button.click(fn=debate_stream, inputs=[topic_input, stance], outputs=output_markdown)
|
| 54 |
+
|
| 55 |
+
# Run the Gradio app
|
| 56 |
+
app.launch(debug=True)
|