Sugamdeol commited on
Commit
eb36fed
·
verified ·
1 Parent(s): 852d9e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -49
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 Meta-Llama-3.1-8B model inference
7
- # Make sure you have set the HUGGING_FACE_HUB_TOKEN environment variable with your access token
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 and well-structured argument for the following debate topic:
17
  Topic: {topic}
18
  Stance: {stance}
19
 
20
- Your response should include:
21
- 1. A clear main claim
22
- 2. Three strong supporting points with evidence
23
- 3. A potential counterargument
24
- 4. A rebuttal to that counterargument
25
- 5. A compelling conclusion
26
 
27
- Please ensure your argument is logical, well-reasoned, and persuasive."""
28
-
29
- argument = generate_text(argument_prompt, max_length=800)
30
 
31
  # Generate a counterargument
32
- counter_prompt = f"""Generate a strong counterargument for the following debate topic:
33
  Topic: {topic}
34
  Original Stance: {stance}
35
 
36
- Your response should include:
37
- 1. A clear counter-claim
38
- 2. Three rebuttals to the original stance's likely arguments
39
- 3. A new supporting point for your counter-claim
40
- 4. A conclusion that reinforces your position
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=800)
45
 
46
- # Generate analysis and additional content
47
- analysis_prompt = f"""Provide a comprehensive analysis of the debate on the following topic:
48
  Topic: {topic}
49
 
50
- Your analysis should include:
51
- 1. Topic categorization (e.g., Politics, Economics, Technology, Ethics)
52
- 2. Three key ethical considerations related to this topic
53
- 3. Four thought-provoking discussion questions to further explore the topic
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=800)
60
 
61
  return f"""Argument ({stance}):
62
  {argument}
@@ -69,16 +59,16 @@ Analysis:
69
 
70
  def suggest_topic():
71
  topics = [
72
- "Should artificial general intelligence development be regulated globally?",
73
- "Is universal basic income a viable solution to technological unemployment?",
74
- "Should human genetic enhancement be allowed for non-medical purposes?",
75
- "Is space colonization necessary for the long-term survival of humanity?",
76
- "Should social media platforms be held legally responsible for user-generated content?",
77
- "Is nuclear fusion the ultimate solution to the global energy crisis?",
78
- "Should autonomous weapons systems be completely banned in warfare?",
79
- "Is a carbon tax the most effective way to combat climate change?",
80
- "Should governments implement a four-day work week to improve work-life balance?",
81
- "Is the current patent system hindering rather than promoting innovation?"
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="Advanced AI-powered Debate Assistant (Meta-Llama-3.1-8B)",
94
- description="Enter a debate topic and choose a stance to generate comprehensive arguments, counterarguments, and analysis.",
95
  examples=[
96
- ["Should artificial general intelligence development be regulated globally?", "For"],
97
- ["Is universal basic income a viable solution to technological unemployment?", "Against"],
98
- ["Should human genetic enhancement be allowed for non-medical purposes?", "For"]
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