Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
-
import os
|
5 |
|
6 |
-
# Set up the client for
|
7 |
-
|
8 |
-
client = InferenceClient("meta-llama/Meta-Llama-3.1-8B", token=os.environ.get("HUGGING_FACE_HUB_TOKEN"))
|
9 |
|
10 |
def generate_text(prompt, max_length=500):
|
11 |
response = client.text_generation(prompt, max_new_tokens=max_length, temperature=0.7)
|
@@ -13,50 +11,42 @@ def generate_text(prompt, max_length=500):
|
|
13 |
|
14 |
def debate_assistant(topic, stance):
|
15 |
# Generate the main argument
|
16 |
-
argument_prompt = f"""Generate a comprehensive
|
17 |
Topic: {topic}
|
18 |
Stance: {stance}
|
19 |
|
20 |
-
|
21 |
-
1.
|
22 |
-
2. Three
|
23 |
-
3.
|
24 |
-
4.
|
25 |
-
5.
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
argument = generate_text(argument_prompt, max_length=800)
|
30 |
|
31 |
# Generate a counterargument
|
32 |
-
counter_prompt = f"""Generate a
|
33 |
Topic: {topic}
|
34 |
Original Stance: {stance}
|
35 |
|
36 |
-
|
37 |
-
1.
|
38 |
-
2. Three rebuttals
|
39 |
-
3.
|
40 |
-
4.
|
41 |
-
|
42 |
-
Ensure your counterargument is logical, well-supported, and addresses key points of the original stance."""
|
43 |
|
44 |
-
counterargument = generate_text(counter_prompt, max_length=
|
45 |
|
46 |
-
# Generate analysis
|
47 |
-
analysis_prompt = f"""
|
48 |
Topic: {topic}
|
49 |
|
50 |
-
|
51 |
-
1. Topic categorization
|
52 |
-
2.
|
53 |
-
3.
|
54 |
-
4. A brief overview of the historical context or background of this debate
|
55 |
-
5. Two potential real-world implications or consequences of this debate
|
56 |
-
|
57 |
-
Please provide a balanced and insightful analysis."""
|
58 |
|
59 |
-
analysis = generate_text(analysis_prompt, max_length=
|
60 |
|
61 |
return f"""Argument ({stance}):
|
62 |
{argument}
|
@@ -69,16 +59,16 @@ Analysis:
|
|
69 |
|
70 |
def suggest_topic():
|
71 |
topics = [
|
72 |
-
"Should artificial
|
73 |
-
"Is universal basic income a viable
|
74 |
-
"Should
|
75 |
-
"Is space
|
76 |
-
"Should
|
77 |
-
"Is nuclear
|
78 |
-
"Should
|
79 |
-
"Is a
|
80 |
-
"Should
|
81 |
-
"Is
|
82 |
]
|
83 |
return random.choice(topics)
|
84 |
|
@@ -90,12 +80,12 @@ iface = gr.Interface(
|
|
90 |
gr.Radio(["For", "Against"], label="Stance")
|
91 |
],
|
92 |
outputs=gr.Textbox(label="Generated Debate Content"),
|
93 |
-
title="
|
94 |
-
description="Enter a debate topic and choose a stance to generate
|
95 |
examples=[
|
96 |
-
["Should artificial
|
97 |
-
["Is universal basic income a viable
|
98 |
-
["Should
|
99 |
]
|
100 |
)
|
101 |
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import random
|
|
|
4 |
|
5 |
+
# Set up the client for FLAN-T5-XL model inference
|
6 |
+
client = InferenceClient("google/flan-t5-xl")
|
|
|
7 |
|
8 |
def generate_text(prompt, max_length=500):
|
9 |
response = client.text_generation(prompt, max_new_tokens=max_length, temperature=0.7)
|
|
|
11 |
|
12 |
def debate_assistant(topic, stance):
|
13 |
# Generate the main argument
|
14 |
+
argument_prompt = f"""Generate a comprehensive argument for the following debate topic:
|
15 |
Topic: {topic}
|
16 |
Stance: {stance}
|
17 |
|
18 |
+
Include:
|
19 |
+
1. Main claim
|
20 |
+
2. Three supporting points
|
21 |
+
3. Potential counterargument
|
22 |
+
4. Rebuttal
|
23 |
+
5. Conclusion"""
|
24 |
|
25 |
+
argument = generate_text(argument_prompt, max_length=600)
|
|
|
|
|
26 |
|
27 |
# Generate a counterargument
|
28 |
+
counter_prompt = f"""Generate a counterargument for the following debate topic:
|
29 |
Topic: {topic}
|
30 |
Original Stance: {stance}
|
31 |
|
32 |
+
Include:
|
33 |
+
1. Counter-claim
|
34 |
+
2. Three rebuttals
|
35 |
+
3. New supporting point
|
36 |
+
4. Conclusion"""
|
|
|
|
|
37 |
|
38 |
+
counterargument = generate_text(counter_prompt, max_length=600)
|
39 |
|
40 |
+
# Generate analysis
|
41 |
+
analysis_prompt = f"""Analyze the debate on the following topic:
|
42 |
Topic: {topic}
|
43 |
|
44 |
+
Provide:
|
45 |
+
1. Topic categorization
|
46 |
+
2. Two ethical considerations
|
47 |
+
3. Three discussion questions"""
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
analysis = generate_text(analysis_prompt, max_length=400)
|
50 |
|
51 |
return f"""Argument ({stance}):
|
52 |
{argument}
|
|
|
59 |
|
60 |
def suggest_topic():
|
61 |
topics = [
|
62 |
+
"Should artificial intelligence be regulated?",
|
63 |
+
"Is universal basic income a viable economic policy?",
|
64 |
+
"Should voting be mandatory?",
|
65 |
+
"Is space exploration a worthwhile investment?",
|
66 |
+
"Should gene editing in humans be allowed?",
|
67 |
+
"Is nuclear energy the solution to climate change?",
|
68 |
+
"Should social media platforms be held responsible for user content?",
|
69 |
+
"Is a four-day work week beneficial for society?",
|
70 |
+
"Should animal testing be banned?",
|
71 |
+
"Is globalization overall positive or negative for developing countries?"
|
72 |
]
|
73 |
return random.choice(topics)
|
74 |
|
|
|
80 |
gr.Radio(["For", "Against"], label="Stance")
|
81 |
],
|
82 |
outputs=gr.Textbox(label="Generated Debate Content"),
|
83 |
+
title="AI-powered Debate Assistant (FLAN-T5-XL)",
|
84 |
+
description="Enter a debate topic and choose a stance to generate arguments, counterarguments, and analysis.",
|
85 |
examples=[
|
86 |
+
["Should artificial intelligence be regulated?", "For"],
|
87 |
+
["Is universal basic income a viable economic policy?", "Against"],
|
88 |
+
["Should gene editing in humans be allowed?", "For"]
|
89 |
]
|
90 |
)
|
91 |
|