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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -87
app.py CHANGED
@@ -1,114 +1,84 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
  import random
 
4
 
5
- # Set up the client for Mistral model inference
6
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
7
 
8
- def generate_text(prompt):
9
- response = client.text_generation(prompt, max_new_tokens=300, temperature=0.7)
10
  return response
11
 
12
- def categorize_topic(topic):
13
- prompt = f"""Categorize the following debate topic into one of these categories: Politics, Economics, Technology, Environment, Social Issues, Ethics, or Other.
14
-
15
- Topic: {topic}
16
-
17
- Category:"""
18
- return generate_text(prompt).strip()
19
-
20
- def generate_structured_argument(topic, stance):
21
- prompt = f"""Generate a structured argument for the following debate topic.
22
  Topic: {topic}
23
  Stance: {stance}
24
 
25
- Your response should follow this structure:
26
- 1. Main claim
27
- 2. Supporting point 1
28
- 3. Supporting point 2
29
- 4. Potential counterargument
30
- 5. Rebuttal to counterargument
31
- 6. Conclusion
32
-
33
- Ensure each point is concise and well-reasoned."""
34
- return generate_text(prompt)
35
 
36
- def generate_structured_counterargument(topic, original_argument):
37
- prompt = f"""Generate a structured counterargument for the following debate topic and argument.
38
- Topic: {topic}
39
- Original Argument: {original_argument}
40
 
41
- Your response should follow this structure:
42
- 1. Main counter-claim
43
- 2. Rebuttal to original supporting point 1
44
- 3. Rebuttal to original supporting point 2
45
- 4. New supporting point for counter-claim
46
- 5. Addressing the original rebuttal
47
- 6. Conclusion
48
 
49
- Ensure each point directly addresses the original argument and provides new insights."""
50
- return generate_text(prompt)
51
-
52
- def assess_argument_quality(argument):
53
- prompt = f"""Assess the quality of the following argument on a scale of 1 to 10, where 1 is very poor and 10 is excellent. Consider factors such as logical coherence, evidence use, and persuasiveness.
54
 
55
- Argument: {argument}
 
 
 
 
56
 
57
- Provide your assessment in this format:
58
- Score: [1-10]
59
- Reasoning: [Brief explanation of the score]"""
60
- return generate_text(prompt)
61
 
62
- def generate_sources(topic):
63
- prompt = f"""Provide a list of 3-5 credible sources that could be used to research the following debate topic:
64
 
 
 
65
  Topic: {topic}
66
 
67
- For each source, provide:
68
- 1. Title
69
- 2. Author or Organization
70
- 3. Brief description (1-2 sentences)
 
 
71
 
72
- Format the response as a numbered list."""
73
- return generate_text(prompt)
74
 
75
- def debate_assistant(topic, stance):
76
- category = categorize_topic(topic)
77
- argument = generate_structured_argument(topic, stance)
78
- counterargument = generate_structured_counterargument(topic, argument)
79
- arg_quality = assess_argument_quality(argument)
80
- counter_quality = assess_argument_quality(counterargument)
81
- sources = generate_sources(topic)
82
-
83
- return f"""Topic Category: {category}
84
-
85
- Argument:
86
- {argument}
87
 
88
- Argument Quality Assessment:
89
- {arg_quality}
90
 
91
  Counterargument:
92
  {counterargument}
93
 
94
- Counterargument Quality Assessment:
95
- {counter_quality}
96
-
97
- Suggested Sources for Further Research:
98
- {sources}"""
99
 
100
  def suggest_topic():
101
  topics = [
102
- "Should artificial intelligence be regulated?",
103
- "Is universal basic income a viable economic policy?",
104
- "Should voting be mandatory?",
105
- "Is space exploration a worthwhile investment?",
106
- "Should gene editing in humans be allowed?",
107
- "Is nuclear energy the solution to climate change?",
108
- "Should social media platforms be held responsible for user content?",
109
- "Is a four-day work week beneficial for society?",
110
- "Should animal testing be banned?",
111
- "Is globalization overall positive or negative for developing countries?"
112
  ]
113
  return random.choice(topics)
114
 
@@ -120,12 +90,12 @@ iface = gr.Interface(
120
  gr.Radio(["For", "Against"], label="Stance")
121
  ],
122
  outputs=gr.Textbox(label="Generated Debate Content"),
123
- title="Advanced AI-powered Debate Assistant",
124
- description="Enter a debate topic and choose a stance to generate structured arguments, counterarguments, quality assessments, and suggested sources.",
125
  examples=[
126
- ["Should artificial intelligence be regulated?", "For"],
127
- ["Is universal basic income a viable economic policy?", "Against"],
128
- ["Should gene editing in humans be allowed?", "For"]
129
  ]
130
  )
131
 
 
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)
12
  return response
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}
63
 
64
  Counterargument:
65
  {counterargument}
66
 
67
+ Analysis:
68
+ {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
  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